EventDispatcherBuilder
Defined in: src/persistence/EventDispatcher.ts:59
Builder state, parameterised by the kinds that have already been
handled. Each .on() call narrows Handled; once Handled
covers every kind in the union, .build()’s return type becomes a
callable (state, event) => state function. Until then it returns
an EventDispatcherIncomplete<missing> that isn’t callable, so the
user sees a type error at the call site.
Type Parameters
Section titled “Type Parameters”S
E extends object
Handled
Section titled “Handled”Handled extends E["kind"]
Methods
Section titled “Methods”build()
Section titled “build()”build(): [
Exclude<E["kind"],Handled>] extends [never] ? (state,event) =>S:EventDispatcherIncomplete<Exclude<E["kind"],Handled>>
Defined in: src/persistence/EventDispatcher.ts:83
Materialise the dispatcher as a single function. Return type is
the callable dispatcher when every variant of E['kind'] is
registered, otherwise EventDispatcherIncomplete<missing>.
When a variant is missing, calling the result like
dispatcher(state, event) produces a TS error naming the missing
kind literal in the type.
Returns
Section titled “Returns”[Exclude<E["kind"], Handled>] extends [never] ? (state, event) => S : EventDispatcherIncomplete<Exclude<E["kind"], Handled>>
on<
K>(kind,handler):EventDispatcherBuilder<S,E,Handled|K>
Defined in: src/persistence/EventDispatcher.ts:69
Register a handler for kind. Returns a new builder type with
K added to the handled set. Re-registering the same kind is a
compile error (the type-level Exclude forbids it).
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
handler
Section titled “handler”(state, event) => S
Returns
Section titled “Returns”EventDispatcherBuilder<S, E, Handled | K>
