Pocak
State machine
States:
// enumconst Turnstil = 0: "Locked" 1: "Unlocked" Locked: 0 Unlocked: 1;
Inputs or actions that are taken to change the state:
const coin = { if current === statesLocked return statesUnlocked; return current;}; const push = { if current === statesUnlocked return statesLocked; return current;};
To create a state machine you can use enums or arrays.
const state coin push = ; // OR const state coin push = ; // default state is the first enum or the first element in the array ; // => Locked ; ; // => Unlocked ; ; // => Locked
Subscription to state changes is also possible:
state;