UNPKG

@hexworks/cobalt-state

Version:

State machine utility for Cobalt.

26 lines 981 B
import { EventType } from ".."; import { executeWithContext, newState, state } from "../.."; import { FillingForm } from "./FillingForm"; import { WaitingForInput } from "./WaitingForInput"; import { BaseState } from "./schema"; export const Idle = state("Idle") .withSchema(BaseState) .onEntry(executeWithContext(({ userId, id }, { scheduler }) => { return scheduler.schedule({ type: "Prompt", data: { userId }, name: `Prompt user ${userId}`, scheduledAt: new Date(), correlationId: id, }); })) .onExit(executeWithContext(({ id }, { scheduler }) => scheduler.cancelByCorrelationId(id))) .onEvent(EventType.UserInitiatedForm, (transition) => { return transition.transitionTo((data) => newState(FillingForm, data)); }) .onEvent(EventType.PromptSent, (transition) => transition.transitionTo((data) => newState(WaitingForInput, { ...data, bumpCount: 0, }))) .build(); //# sourceMappingURL=Idle.js.map