Call oncreate
functions before updating bindings
#694
Merged
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.
@TehShrike, as is his tendency, found a particularly baffling bug: when you have a binding to a child component's computed value, and the computed value is dependent on values that are set during
oncreate
, the observer infinite loop guard (callback.__calling
) prevents any observers of the computed value from being called.Quite possibly the mother of all edge cases, but a bug nonetheless. The solution seems to be to ensure that
oncreate
functions are called before parents are notified of the values of bindings to their children (since updating those bindings is what indirectly triggers the observers before they're 'ready').Not 100% certain I've fully understood and articulated this bug, but it seems at least probable that this is the correct fix.
Also mentioned by @TehShrike but not addressed in this PR — the computed value in question is recomputed for each component that gets created. In the attached test, that means it's computed three times (once initially, then twice more for 'first thing' and 'second thing'). It would be nice to at least coalesce any computations that happen during
oncreate
, so that it only fires twice no matter how many components there are.