EntityAdapter selectAll ordering stability when sortComparer omitted and sort-relevant properties updated
0 reputation · 22 Nov 2023, 14:56 UTC
0 reputation · 22 Nov 2023, 14:56 UTC
Achieve predictable display order for entity lists derived from selectAll when entities are frequently updated on properties that should affect sort position.
The EntityAdapter only reorders the internal ids array when a sortComparer is provided and an operation mutates that array (add, upsert, remove). An update() that changes a sort-relevant field leaves the ids array reference unchanged, so the memoized selectAll selector returns the same array reference and Angular change detection sees no difference. Without a sortComparer, order reflects insertion sequence, which can diverge between eagerly and lazily loaded feature modules. In ngrx v16+ signal-based stores, the interaction between selector memoization and signal equality checks adds another layer of uncertainty about when a new array reference is produced.
selectAll output after a sort-relevant property update without re-adding every affected entity?entityAdapter API expose a built-in mechanism to invalidate the ids ordering on property changes, or must developers dispatch a synthetic action that replaces the ids array?createSelector behavior when the underlying ids array reference is preserved but entity property values change?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.