Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Started replying to @marvinhagemeister on sveltejs/rfcs#5 but got side-tracked by trying to see if we could make our reactive stores glitch-free (i.e. if a derived store depends on
a
andb
, andb
is also a derived store that depends ona
, don't recalculate whena
changes untilb
is also up-to-date).I think this works? But would appreciate a sanity check if anyone is familiar with this problem space...
Explanation: each store's
subscribe
method now takes an optional secondinvalidate
method:When a store's value changes, it should call all the invalidate functions and then call the main callback. Most of the time the second argument is unnecessary, but the
derive
function uses it to update an internal number that keeps track of which inputs are invalid.