Reactive architecture structures software around responses to events. Instead of sequencing actions as “Do X, then Y,” it expresses “When X happens, do Y,” extending event handlers into chains of handlers and pipelines. section 18.3 section 18.25
The pattern reorganizes action sequences in three important ways:
- Decouples effects from their causes: an effect responds to a state change or event regardless of which operation caused it. section 18.11
- Treats steps as pipelines: simple actions and calculations respond to preceding actions and compose into longer sequences. section 18.10 section 18.4
- Creates timeline flexibility: independent handlers can run through shorter timelines when they do not share resources. section 18.14
Updating shopping-cart indicators
Suppose free-shipping icons depend on the current cart. A conventional design updates the icons separately after add, remove, and empty-cart clicks. A reactive design states the rule once: whenever the cart changes, update the icons, regardless of the cause. A ValueCell can hold mutable state and notify watcher functions when its value changes, forming a reactive pipeline. section 18.11 section 18.14 section 18.10
Reactive architecture is useful for web services and user interfaces, but it is not automatically better. Separating causes from effects can improve maintenance and precision, yet may also make ordering less readable or permit unwanted timelines. Apply it where causes and effects need to vary independently. section 18.3 section 18.4
