State Changes with Multiple Dependents
You'll learn how reactive patterns elegantly handle scenarios where changing one piece of state must update multiple parts of your application automatically.
The Coordination Problem
Imagine you're building an e-commerce cart. When the user changes the quantity of an item, you need to update:
- The cart total
- The shipping cost calculation
- The tax display
- A "free shipping threshold" progress bar
- Analytics tracking
Without reactive patterns, you'd manually call all these update functions every time quantity changes. Miss one? Your UI becomes inconsistent. Call them in the wrong order? Bugs appear. Add a new dependent later? You must find every place where quantity changes.
How Reactive Patterns Solve This
Reactive systems (signals, observables, RxJS streams) use automatic dependency tracking. When you change the source state, the system propagates updates to all dependents automatically:
// With reactive patterns (conceptual)
const quantity = signal(1);
const subtotal = computed(() => quantity() * price);
const tax = computed(() => subtotal() * 0.08);
const total = computed(() => subtotal() + tax());
const shippingNeeded = computed(() => total() < 50);
// Change once, everything updates automatically
quantity.set(3); // subtotal, tax, total, shippingNeeded all recalculate
The pattern creates a dependency graph. Each dependent registers interest in its sources. When a source changes, the system walks the graph and updates everything in the correct order, avoiding glitches and stale values.
This is far superior to manual imperative updates where you'd write updateSubtotal(); updateTax(); updateTotal(); updateShipping(); after every change.
Key Takeaway: Reactive patterns eliminate manual coordination when one state change affects many computations or UI elements, automatically propagating updates through dependency graphs and preventing inconsistency bugs.