-
Notifications
You must be signed in to change notification settings - Fork 414
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
Reaction value propagation glitch - the dirty flag is not set #568
Comments
" if you replace (> x 0) with (>= x 0) it works as expected." Just guessing, but x starts at zero, so the first time With the test as Reagent of course sees b depends on x, so I suspect that if the (Aside: Some reactive mechanisms such as Hoplon/Javelin inspect the code to determine dependencies and would see the potential, but then they are over-depending some of the time, and missing dependencies reached by calling other functions.) FYI, Matrix and JS MobX avoid this by having an independent means of deciding if a given reactive value is up to date. Matrix uses a serial, global "pulse" that gets incremented, in this case, each time x changes. When f decides to read b for the first time, it can see that b is out of date and on the fly recalculates b before returning a value. MobX has a different scheme (forgotten) for deciding if b is current. Without an independent determinant of "up to date", this could be a tough fix. Again, just guessing. |
As @kennytilton wrote, on the first reaction run it sees the old In this case, you can ensure your code always sees the up-to-date value by raising the I tried writing notes on why it works this way several times but hit cases that I don't understand in each case. So currently I don't know if this is something we can fix. It is probably related to |
@Deraen wrote: "In this case, you can ensure your code always sees the up-to-date value by raising the @b' outside the if form. " The problem with moving the @b' outside the IF is that an unnecessary dependency is created if the IF condition is false. This is an innocuous excess if the unnecessary propagation leads to a trivial amount of processing. Perhaps worse is that Reagent programmers writing natural conditional code do need to stay on their toes in this regard. All that said, again, there likely is no way around this, and again, I wrote an awful lot of reactive code successfully in my own framework before fixing the same issue. |
It's quite finicky to reproduce. In the code below, if you replace
(> x 0)
with(>= x 0)
it works as expected.When the breakpoint is hit, you can see in the Scope panel that
a
is marked as dirty butb
is not and still has the previous value.I would expect that
(not= x b)
is never triggered becausex + 10 - 10
should be equal tox
.The text was updated successfully, but these errors were encountered: