@hyperfrontend/state-machine/eventsevents
Event-driven state primitives: a small pub/sub registry used as a building block by other state-machine pieces.
Events exposes on over typed event names, and derives each event from the state changes its own dispatch produces, so components can subscribe to lifecycle and state-change notifications without coupling to the dispatcher that publishes them. Used internally by LifecycleAwareComponent and Store to surface state transitions; available on its own for application code that wants the same shape without dragging in a full store.
API Reference§
◇ Classes
Event system that tracks state changes and dispatches events to registered handlers.
Constructor
§
new Events( )Methods
Reduces an action into the internal store and dispatches the events the resulting state change implies.
Handlers run synchronously before this call returns, once for every event whose flag went from off to on, in the order the events are declared and then in registration order. An action that leaves the derived state unchanged fires nothing.
Handlers run synchronously before this call returns, once for every event whose flag went from off to on, in the order the events are declared and then in registration order. An action that leaves the derived state unchanged fires nothing.
Registers a handler for one event name.
The handler runs each time the matching derived-state flag turns on, so it fires on every transition into that state rather than once. Registration is additive: a handler registered twice runs twice, and nothing is deduplicated.
The handler runs each time the matching derived-state flag turns on, so it fires on every transition into that state rather than once. Registration is additive: a handler registered twice runs twice, and nothing is deduplicated.
Example
Registering event handlers
const events = new Events()
events.on(event.Done, () => console.log('Operation completed'))
events.dispatch(success())