whenEventType
whenEventType<
E
,K
>(type
:K
,fn
:EntryListener
<E
& {type
:K
; }>): (ev
:E
) =>void
Defined in: factory-machine-hooks.ts:183
Creates an entry listener that triggers when the event’s type matches the given event type.
Type Parameters
Section titled “Type Parameters”Type Parameter | Description |
---|---|
E extends FactoryMachineEvent <any > | FactoryMachineEvent type |
K extends string | Event type |
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
type | K | The event type to match |
fn | EntryListener <E & { type : K ; }> | EntryListener to invoke when matched |
Returns
Section titled “Returns”An entry listener for the specified event type
(
ev
:E
):void
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | E |
Returns
Section titled “Returns”void
Example
Section titled “Example”setup(machine)( whenEventType("activate", handleActivate),);
Source
Section titled “Source”Useful for running logic when a specific event type is triggered in a state machine.
export const whenEventType = < E extends FactoryMachineEvent<any>, K extends E["type"],>( type: K, fn: EntryListener<E & { type: K }>) => when<E>((ev) => ev.type === type, fn as any);