This demo shows the XState-style branching model: on every coin, the machine tries the unlock branch first, then falls back to a targetless transition that keeps counting coins while staying locked.
Current State
locked
Gate Status
Locked
Coins In State
0
Total Inserted
0
Last Branch
Waiting for coin
Recent History
While the machine is locked, everyINSERT_COINevent checks the array top to bottom.
If the first branch's guard passes, the machine unlocks. Otherwise the fallback branch runs and the state stays locked while context still updates.
INSERT_COIN: [
{
guard: ({ context }) => context.coins + 1 >= 3,
target: 'unlocked',
actions: [
assign(({ context }) => ({
coins: context.coins + 1,
})),
],
},
{
actions: [
assign(({ context }) => ({
coins: context.coins + 1,
})),
],
},
]