Skip to content
English

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.

S

E extends object

Handled extends E["kind"]

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.

[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).

K extends string

K

(state, event) => S

EventDispatcherBuilder<S, E, Handled | K>