Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hierarchy array #6

Open
ricardovf opened this issue Oct 25, 2010 · 1 comment
Open

Hierarchy array #6

ricardovf opened this issue Oct 25, 2010 · 1 comment

Comments

@ricardovf
Copy link

Hi, First of all, congrats on the GREAT work! Ill be trying it in my projects from now.

My Web App is a reporting aplication, and it uses AJAX to load reports, when selected from the menu.

I need to do something like Hierarchy tags. Ill do an exemple:

Supose i have 2 functions requested via AJAX. One is for reports, and it have aditional configs (like id) and the other doesnt.

Report A) index.php/#{"page":{"name":"reports","id":"25648"},"something":"111"}
Report B) index.php/#{"page":{"name":"reports","id":"48441"},"something":"111"}
Report B+config) index.php/#{"page":{"name":"reports","id":"48441","vision":"xxx"},"something":"111"}
Help Page) index.php/#{"page":{"name":"help"},"something":"111"}

On the Report B+config, i would like to register something like:
HM.addEvent('page.vision-changed',function...

Note the page.vision syntax. Would it be posible? An array syntax. Maybe only 2 or 3 levels are needed... (no recursion needed)

There is another thing. As the reports are loaded via AJAX, they need to register on the HM to listen to events. But when i load one of them the second time, they register again for listening. So the solution i found was to use HM.removeEvents('-something:changed');
Is there a better way?

If you have more tips on AJAX+HistoryManager, please let me know!

Thx in advance!

@arieh
Copy link
Owner

arieh commented Oct 26, 2010

Hey!
Great to hear you're finding use for it.
For q1 - anything you can do with JSON, you can do with HM. But HM doesn't do deep compares - it only compare the JSON string of top level arguments (page). So whay I would do is either:

  1. Have a separate handler for each page - HM.set('page.help',{'id':111}); note that a variable name can be what ever you want as long as it's a string.
  2. Have a separate handler for name: HM.set('name','help').set('id',222); Not sure if this would fit your scenario.

As for AJAX - It would seem you problem is a standard event problem. Yes, what you are looking for is the remove event. This is a very standard (yet awkward). You can try and implement the addEventOnce paradigm if you wish. What I do is:
http://jsfiddle.net/ariehg/EzG25/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants