Reactive State Bus Pattern

Reactive State Bus Pattern

A shared mutable key-value store with a subscriber registry — input components write to it, output components subscribe to the keys they care about. When a key changes, all subscribers for that key are notified synchronously. No external reactive library required.

The pattern is a minimal pub/sub implementation: Map<string, unknown> for state, Map<string, Set<fn>> for subscribers. A subscriber registers against a key and receives a function to unsubscribe. The bus has no equality check — every set notifies, even if the value is unchanged. This keeps the logic simple and predictable at the cost of some redundant renders, which is an acceptable trade in a component-count-bounded system.

The payoff is ownership: when the reactive pattern is simple enough to fit in ~50 lines, importing a signals library or MobX adds more complexity than it removes. The bus becomes part of the system contract rather than a third-party dependency.


Source: data-app-factory — #004 Renderer: StateBus See also: Template Variables as Implicit Dependency Declarations, Config Schema and Runtime Unified in a Single Renderer