Which replies end the call, and how long to wait. See CallOptions.
Returns
CallHandle<EventUnion<EM>, EventUnion<EM>>, A CallHandle: await it for the terminal reply, or for await it for
progress events as they arrive.
Example
example
// Survives a job that streams for minutes; fails a responder that goes quiet for 5s.await store.call("job", "start", { id }, { reply: ["job", "done"], timeoutMs: 5_000 });
// Listen to any item title changeconst off = store.connect( { reducer: 'todos', property: 'items.*.title' }, (chg) => console.log('some title changed'));
Emits a typed event (channel, type, payload).
Events are queued and processed **sequentially** (FIFO).
**Pipeline per event:** the *reduce phase* (steps 1-4) runs **synchronously**,
so getState() reflects the change as soon as emit() returns; the *effect
phase* (step 5) runs afterwards, asynchronously.
1. **Deduplication** (opt-in) - Skip when content-dedup is enabled (dedupWindowMs > 0) or a matching dedupKey recurs; off by default
2. **Middleware** (sync) - Pre-reducer hooks; may cancel by returning false
3. **Reducers** (sync) - every matching slice is *staged*; nothing is written yet, so a refusal from the last reducer still stops the first one's write
4. **Commit + subscribers** (sync) - all staged slices are assigned under one new root, then event subscribers (committed, then written when state actually changed), then coarse listeners
5. **Effects** (async) - side-effects keyed by (channel, type); the returned promise resolves once they complete
**Change Detection**: Uses reference equality (===) on this.state to determine
if any slice changed. Works because the commit builds a new state reference via
shallow spread when any slice changes.
Subscribe to events by channel and type.
Event subscriptions are intended for the View layer (e.g., React components)
to react to events without affecting the event flow. They are fire-and-forget
and cannot cancel event propagation.
**Phases:**
- 'committed' (default): Events that passed middleware and reached reducers.
Notified after reducers, before effects.
- 'uncommitted': Events rejected by middleware. Notified immediately after rejection.
- 'written': Events that actually changed state. Stricter than committed, which
fires for every event a store accepts including one with no reducers at all.
- 'all': Both committed and uncommitted events. Handler receives the phase parameter
to distinguish between the two. Deliberately not written as well: an event that
writes is also committed, so folding it in would notify every existing all
subscriber twice for one event.
**Replay:** a handler is not called while devtools is replaying, unless it opted in with
{ duringReplay: true }.
Subscribe to events by channel and type.
Event subscriptions are intended for the View layer (e.g., React components)
to react to events without affecting the event flow. They are fire-and-forget
and cannot cancel event propagation.
**Phases:**
- 'committed' (default): Events that passed middleware and reached reducers.
Notified after reducers, before effects.
- 'uncommitted': Events rejected by middleware. Notified immediately after rejection.
- 'written': Events that actually changed state. Stricter than committed, which
fires for every event a store accepts including one with no reducers at all.
- 'all': Both committed and uncommitted events. Handler receives the phase parameter
to distinguish between the two. Deliberately not written as well: an event that
writes is also committed, so folding it in would notify every existing all
subscriber twice for one event.
**Replay:** a handler is not called while devtools is replaying, unless it opted in with
{ duringReplay: true }.
Subscribe to reducer, middleware and effect registrations.
Delivered as an array, one batch per public call: replaceReducers unmounts and then
remounts, and a per-change observer would see a spurious unmount of a slice that is only
being updated. Observers run after the state broadcast, and a registration made by an
observer is queued rather than delivered re-entrantly.
Replay never produces a change, so there is no duringReplay option here. dispose()
fires nothing.
Subscribe to reducer, middleware and effect registrations.
Delivered as an array, one batch per public call: replaceReducers unmounts and then
remounts, and a per-change observer would see a spurious unmount of a slice that is only
being updated. Observers run after the state broadcast, and a registration made by an
observer is queued rather than delivered re-entrantly.
Replay never produces a change, so there is no duringReplay option here. dispose()
fires nothing.
Subscribes to **coarse-grained** commits (called once per successful event, only if state changed).
**Use Case**: React's useSyncExternalStore or similar external store integrations.
signature
subscribe(fn): () => void
Subscribes to **coarse-grained** commits (called once per successful event, only if state changed).
**Use Case**: React's useSyncExternalStore or similar external store integrations.
Parameters
Name
Type
Description
fn
() => void
Listener invoked after reducers/effects have run and state has changed.
Returns
() => void, Unsubscribe function.
Example
example
const off = store.subscribe(() => console.log('state committed'));// Later:off();