Skip to content

Instantly share code, notes, and snippets.

@nkooman
Created Sep 15, 2021
Embed
What would you like to do?
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const States = {
IDLE: 'IDLE',
CHECKING: 'CHECKING',
RESETTING: 'RESETTING',
REVEALING: 'REVEALING'
};
const Events = {
IDLE: {
CLICK: 'CLICK'
},
CHECKING: {
FACEDOWN_FILLED: 'FACEDOWN_FILLED',
FACEDOWN_EMPTY: 'FACEDOWN_EMPTY'
},
REVEALING: {
DONE: 'DONE'
},
RESETTING: {
FACEUP_FILLED: 'FACEUP_FILLED',
FACEUP_EMPTY: 'FACEUP_EMPTY'
}
};
const stockMachine = Machine({
id: 'stock',
initial: States.IDLE,
context: {
retries: 0
},
states: {
[States.IDLE]: {
on: {
[Events.IDLE.CLICK]: States.CHECKING
}
},
[States.CHECKING]: {
on: {
[Events.CHECKING.FACEDOWN_FILLED]: States.REVEALING,
[Events.CHECKING.FACEDOWN_EMPTY]: States.RESETTING
}
},
[States.REVEALING]: {
on: {
[Events.REVEALING.DONE]: States.IDLE
}
},
[States.RESETTING]: {
on: {
[Events.RESETTING.FACEUP_FILLED]: States.REVEALING,
[Events.RESETTING.FACEUP_EMPTY]: States.IDLE
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment