fix(loops): each/filter reacts to outer-scope dependencies (#335) - #336
Merged
Conversation
The loop's update watcher was only keyed on the listPath expression (e.g. "items"), so key-scoped notifications for outer-scope variables read during filter evaluation (e.g. "showActive") were silently skipped. Additionally, the same-reference optimisation short-circuited the update before the filter could re-evaluate when the source array reference was unchanged. Two changes: 1. Call _watchExpr for filterExpr and sortProp so their root keys are unioned into the update watcher's _keys set. 2. Bypass the same-reference optimisation when a filter expression exists, since the filter result can change even when the source array hasn't. Closes #335
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #335. A loop's filter/sort expression referencing an outer-scope state variable now re-evaluates when that variable changes.
Root cause (two parts, src/directives/loops.js):
_notifyMetaskipped it when an outer-scope var (e.g. showActive, a model-bound query) changed.Fix: subscribe the filter and sort expressions' root keys to the update watcher (union into _keys), and bypass the same-reference guard when a filter expression exists.
Regression: 3 unit tests (toggle re-filter, search/includes re-filter, keyed loop outer-scope filter) + 2 e2e fixtures/tests. Full suite 2287/2287. dist rebuilt. Verified live: toggling an outer var now re-filters the list (was stale past 3s).