liveBook · Manning

Side effect

As explained in Modern Angular

A side effect is an operation performed by a computation that changes state or interacts with something outside the computation's returned value.

A side effect is an operation performed when a changing value causes an action beyond producing that value. Logging the latest signal value to localStorage is one example. section 6.1.2

Signals provide a clean place for effects: register a callback that runs when the signals it reads change. Angular tracks those dependencies and disposes the subscription when the component is destroyed. section 6.8

Keep side effects separate from signal value updates:

  • Use an effect callback for actions triggered by signal changes. section 6.1.2 section 6.8
  • Keep update callbacks pure: they should return the new value without changing other properties or signals. section 6.2.2
  • Avoid updating another signal inside an update callback, because it can create systemic data-flow problems. section 6.2.2

Persisting a changing value

A signal containing a user preference can trigger an effect that writes its latest value to localStorage. The signal remains responsible for representing state; the effect handles the external interaction. section 6.1.2

How Modern Angular covers it

How deep it goes
Defines effects, dependency tracking, cleanup, and purity constraints, but does not detail effect implementation syntax.
Examples
Uses localStorage logging and contrasts clean effects with impure update callbacks that modify other state.
What it assumes
Assumes familiarity with changing values and signals while defining side effects through reactive callbacks.
What you can do after
Apply it via Angular signals by separating external actions from pure state-update callbacks.
How it connects
Connects side effects with signals, RxJS observables, and computed signals.

Also explained in

Compare how 24 books explain side effect →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.