UNPKG

@empathyco/x-components

Version:
31 lines (29 loc) 824 B
/** * Default implementation for the {@link StateMachine}. * * @public */ class StateMachine { constructor(machine) { this.machine = machine; this.currentState = machine.initial; } /** * Determines which state will be the next to be transitioned. * * @param event - The event to determine which state is the new one to be * transitioned. * * @public */ transition(event) { const currentState = this.machine.states[this.currentState]; if (currentState[event]) { /* Typescript is not detecting the type guard in the previous if so we have to force it to be defined */ this.currentState = currentState[event]; } } } export { StateMachine }; //# sourceMappingURL=state-machine.service.js.map