Updating State Immutably
Apply immutable updates to signal state.
Why Immutability
Signals detect change by reference. If you mutate an array or object in place, the reference stays the same and dependent computed() signals may not recompute. Always produce a new reference.
The Mutation Trap
Pushing into an existing array mutates it without changing the reference. Avoid this.
// BAD: mutates in place, reference unchanged
this._items.update(list => { list.push(item); return list; });All lessons in this course
- Signal Stores in Services
- Deriving State with computed
- Updating State Immutably
- Connecting Signals and RxJS