HistoryManager icon indicating copy to clipboard operation
HistoryManager copied to clipboard

Hierarchy array

Open ricardovf opened this issue 14 years ago • 1 comments

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!

ricardovf avatar Oct 25 '10 20:10 ricardovf

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/

arieh avatar Oct 26 '10 06:10 arieh