Introduce level property to allow sorting of stores in computed#145
Conversation
198734b to
2732b92
Compare
| }) | ||
|
|
||
| equal(values, ['a0b0']) | ||
| equal(values, ['000']) |
There was a problem hiding this comment.
Now I see why the letters are important: turned out there was a bug with the order of stores in callback. Thanks!
UPD: The letters are restored, bug is fixed.
|
I am right now in the travel and will think about it after tomorrow. Can you add more complex tests for now to be sure for edge cases? |
Sure, will do it tomorrow. |
|
Well, I guess the order of stores passed to a computed was only a part of the problem. |
|
@ai Take a look on it please. Currently the Now it much more complicated than it was before, so I'm not sure it's worth it. But I also added some more complicated test cases, and almost all of them (2, 3, and 4) are failing, if I run them on the |
| unsubscribe() | ||
| }) | ||
|
|
||
| test('prevents diamond dependency problem 4 (complex)', () => { |
There was a problem hiding this comment.
Should I add a scheme for the data flow is this test? I think without a scheme nobody can understand it.
|
Thanks. Released in 0.7.2. |
Let's consider following example:
The example above has following structure:
A -> B, B -> C, BC -> DIt turns out that the problem is caused by the order in which listeners are added to the
bstore. The order of listeners follows the order of stores, passed tod. Since in the array[b, c]bcomes first,dsubscribes tob, then toc, and only thencsubscribes tob. Sobwill notifydbeforec. Passing[c, b]solves the problem.Letting users to manage the order of stores might not be the best option, since the relations between stores can be tricky and will cause bugs.
In my proposed solution I added to
atoma new propertylevel. Usinglevelthe computed store can sort passed stores in descending order and subscribe to them in the right order.I also extended the test for the diamond problem, now it handles both
A -> B, A -> C, BC -> DandA -> B, B -> C, BC -> Dcases.Intuition tells me that there might be more elegant solutions for the problem, especially using
notifyIdandlistenerQueue. I hope at least my explanation of the issue will be useful.