value subscriber runs before option subscriber #28
Comments
Except for some special cases a JavaScript object will usually be traversed in the order it has been defined. |
I had this for options:
When passed to options the sort couldn't be predicted. I had to use a list with [{ value: 2012, html: 2012}...] for options to ensure order was maintained. This is clearly one of those cases where order isn't maintained. This case generally doesn't appear in config options. However, it's an obscure problem that isn't obvious to casual observers. I think the only way to do it would be to give each subscriber some sort of priority and apply them in that order or to maintain a list of the order to apply them. This would of course be a pain in the ass. You can also allow each subscriber to define an "after" subscriber for which you can determine dependency order, but that's a bit complicated too. I'll think about it and see if I can come up with a simpler option and send you a pull request. |
That is exactly the case where it doesn't work. V8 (Chrome) orders by the actual value, all the others when it has been defined. Unfortunately there is not much that can be done about that (except for being able to pass an array to the options value for years).
This would assure that the options subscriber is run before if an option key exists. |
Looks good. I thought it would be fun to figure out a simple dependency graph in JS https://gist.github.com/1732686 |
I found a much simpler way to do a topological sort on a graph so I updated the gist. |
This looks great, thanks! I will work on it on the weekend and hopefully get 0.1.4 finished up and released with the fix. |
If you have:
The value subscriber runs first and since there are no options yet, nothing gets selected.
If you reverse the keys:
It works, however since you can't rely on the sort order of javascript object keys the code should make sure to run the value subscriber last (or at least after the options)
The text was updated successfully, but these errors were encountered: