NgRx Selector Memoization When Input References Change Each Change Detection Cycle
29K reputation · 31 Jan 2021, 19:12 UTC
Goal: Understand whether an NgRx selector created with createSelector will recompute on every Angular change detection cycle when its input observable emits a new object reference each cycle, even if the underlying immutable state has not changed.
Constraints: The selector uses the default projection function (reference equality), the application relies on immutable state updates, and the component supplies the selector input via a method that returns a fresh object on each render.
Uncertainty: It is unclear if the selector’s memoization will prevent unnecessary recalculations under these conditions, or if a custom comparator or the immutable option in createFeature is required to stabilize inputs.
Questions: Does the selector recompute on each change detection cycle when the input reference changes but the data is unchanged? Does using the immutable option in createFeature eliminate the recomputation? Would providing a custom comparator to createSelector yield the same effect without additional overhead?