LearnNewsExamplesServices
Frontmatter
id9434
titleTreeStore: Decouple clearFilters() from legacy allItems pattern
stateClosed
labels
enhancementairefactoringarchitecture
assigneestobiu
createdAtMar 10, 2026, 3:26 PM
updatedAtMar 10, 2026, 4:28 PM
githubUrlhttps://github.com/neomjs/neo/issues/9434
authortobiu
commentsCount1
parentIssue9404
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMar 10, 2026, 4:28 PM

TreeStore: Decouple clearFilters() from legacy allItems pattern

Closed v12.1.0 enhancementairefactoringarchitecture
tobiu
tobiu commented on Mar 10, 2026, 3:26 PM

Goal

Refactor clearFilters() in TreeStore to utilize the native _keptNodes masking logic rather than relying on Collection.Base's allItems cloning fallback.

Context

Standard Neo.data.Store filtering works by cloning the entire dataset into an allItems collection so it remembers the unfiltered state. Our custom TreeStore.filter() bypasses this because it relies entirely on #allRecordsMap as the ultimate source of truth, masking the projection using a _keptNodes Set. Currently, if a developer clears the filters, it might trigger the inherited Collection.Base logic, which expects allItems to exist.

Acceptance Criteria

  • Override clearFilters() in TreeStore.mjs.
  • The method should nullify or clear this._keptNodes.
  • The method should completely rebuild the flat _items projection (collectVisibleDescendants) from the root nodes.
  • Do not let it fallback to super.clearFilters() if that triggers allItems manipulation.
  • Fire a standard filter event with isFiltered: false.
  • Write a unit test verifying that clearFilters() successfully restores the entire visible tree hierarchy without data loss.
tobiu added the enhancement label on Mar 10, 2026, 3:26 PM
tobiu added the ai label on Mar 10, 2026, 3:26 PM
tobiu added the refactoring label on Mar 10, 2026, 3:26 PM
tobiu added the architecture label on Mar 10, 2026, 3:26 PM
tobiu added parent issue #9404 on Mar 10, 2026, 3:27 PM
tobiu assigned to @tobiu on Mar 10, 2026, 3:29 PM
tobiu referenced in commit e78c93b - "TreeStore: Decouple clearFilters() from legacy allItems pattern (#9434)" on Mar 10, 2026, 4:27 PM
tobiu
tobiu Mar 10, 2026, 4:27 PM

Input from Gemini 3.1 Pro:

✦ I have overridden clearFilters() in TreeStore.mjs to decouple it from the legacy allItems pattern.

The new implementation simply clears me._keptNodes and forces a full re-projection of the _items array directly from the structural maps (#childrenMap), ensuring a perfectly clean recovery from a filtered state without relying on clones.

Bonus: I also uncovered and fixed a subtle bug where me.count wasn't being correctly updated after filter() and clearFilters() re-projections. Both methods now explicitly set me.count = me._items.length.

Unit tests have been added to verify that clearFilters() successfully restores the entire visible hierarchy and resets all states. The commit has been pushed to the dev branch.

tobiu closed this issue on Mar 10, 2026, 4:28 PM