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.
- 'all': Both committed and uncommitted events. Handler receives the phase parameter
to distinguish between the two.
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.
- 'all': Both committed and uncommitted events. Handler receives the phase parameter
to distinguish between the two.
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();