-
Notifications
You must be signed in to change notification settings - Fork 10
fix: fixing asymmetric diamond dependency problem #31
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
fix: fixing asymmetric diamond dependency problem #31
Conversation
bc06eb3
to
6e0885f
Compare
Codecov Report
@@ Coverage Diff @@
## master #31 +/- ##
==========================================
+ Coverage 98.46% 98.75% +0.29%
==========================================
Files 1 1
Lines 130 161 +31
Branches 24 28 +4
==========================================
+ Hits 128 159 +31
Partials 2 2
Continue to review full report at Codecov.
|
e8555cb
to
d30077b
Compare
@pkozlowski-opensource Feel free to have a look at this PR and to give some feedback if you have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine on my side, but probably need another look from another reviewer.
@maxokorokov, can you have a look ?
@divdavem oh, cool to see that you are digging into the batched and glitch-free propagation algorithm! I don't think I will have time to do any meaningful review so I don't want to block progress here. |
@fbasso Thank you for your review! |
@pkozlowski-opensource Thank you for your comment! It is great to hear from you! I understand you are very busy! |
22c55eb
to
49136b6
Compare
49136b6
to
9039b73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, apart from invalidate/revalidate
naming.
I find revalidate
confusing, seems like uninvalidate
would fit better, but I don't think it's a word. And I don't have better options.
freeze/unfreeze
, pause/resume
, disable/enable
, I don't know...
@maxokorokov Thank you for your review! |
This is a big refactoring of the algorithm so that the asymmetric diamond dependency problem is fixed:
For info, the asymmetric diamond dependency bug is also present in svelte stores:
https://svelte.dev/repl/445983f3fdfe4db9ab860d88642f1989?version=3.48.0
A possible workaround (both in ngx-tansu and in svelte stores) is to transform it into the symmetric diamond dependency problem:
But it is better to have a proper fix. That's why I am opening this PR!
This PR makes
invalidate
calls recursive so that the whole tree of dependent stores is prevented from updating while values are changed. As a consequence, there is a need of the reverserevalidate
operation (equivalent tonext
with the same value, but avoiding re-computations) in case the value does not change.I have not measured the impact on performance in case the tree of dependencies is big. The
invalidate
listener functions should be kept as small and quick as possible (just switching a boolean and propagating the info).This PR adds several tests for different cases in addition to the asymmetric diamond dependency case.