-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The problem:
When you add rules and sub-rules them run dispatch() it runs all rules, however if more rules are added after dispatch() and the same is executed again, those new rules are ignored.
Another problem is when you remove rules, they don't dispatch the leave event, before they get removed by GC they should run leave to cleanup their changes on DOM (if they're in match state).
Solution:
Every time that a match is triggered, immutable copy of the tree inside the router is generated, if there is an old tree, it compares with the old tree, all the removed elements are queued in order to the leave event stack, when a element is added it will be tested to run the enter event in case of match it is added to the enter event stack.
Optimizations:
match event doesn't need to run on the elements that doesn't suffer changes, since the URI didn't change, this will decrease the times that match is triggered and make it work like enter/change events.
New tests:
- Ensure that
matchisn't trigger multiple times, if the URI doesn't change. - Ensure that a rule in match state triggers
leaveif removed from the router and same router is dispatched.- Should trigger if the URI in the router change.
- Should trigger if the URI in the router doesn't change.
- Ensure that all added rules are executed if they're added and their parent is a matching router or rule.
Good to have:
To make this happen, the router could dispatch an trigger or dispatched event, to allow apps to listen every time the dispatch method from a router is triggered, since match will only dispatch if there were changes in the URI like change does.