@hexworks/cobalt-state
Version:
State machine utility for Cobalt.
27 lines • 1.01 kB
JavaScript
import { Reporting, WaitingForInput } from ".";
import { EventType } from "..";
import { executeWithContext, newState, state } from "../..";
import { StateType } from "./StateType";
import { BaseState } from "./schema";
export const FillingForm = state(StateType.FillingForm)
.withSchema(BaseState)
.onEntry(executeWithContext(({ userId, id }, { scheduler }) => {
return scheduler.schedule({
type: "Timeout",
data: { userId },
name: `Timeout user ${userId}`,
scheduledAt: new Date(),
correlationId: id,
});
}))
.onExit(executeWithContext(({ id }, { scheduler }) => scheduler.cancelByCorrelationId(id)))
.onEvent(EventType.TimedOut, (transition) => transition.transitionTo((state) => newState(WaitingForInput, {
...state,
bumpCount: 0,
})))
.onEvent(EventType.FormSubmitted, (transition) => transition.transitionTo((state, { data }) => newState(Reporting, {
...state,
data,
})))
.build();
//# sourceMappingURL=FillingForm.js.map