Skip to content

Instantly share code, notes, and snippets.

@ajs139
Created April 3, 2020 14:39
Show Gist options
  • Save ajs139/52ff6622f048b6a8b4050cce3db3d3c3 to your computer and use it in GitHub Desktop.
Save ajs139/52ff6622f048b6a8b4050cce3db3d3c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const states = {
idle: {
on: {
START: 'started',
},
},
started: {
entry: ['start'],
on: { CLOSE: 'closed', COMPLETE: 'completed', PAUSE: 'paused' },
exit: [assign({ started: true })],
},
paused: {
entry: ['pause'],
on: { RESUME: 'resumed', CLOSE: 'closed' },
},
completed: {
entry: ['complete'],
},
};
const transientStates = {
resumed: {
entry: ['resume'],
on: {
'': 'started',
},
},
closed: {
entry: ['close'],
on: {
'': 'idle',
},
},
};
const lessonMachine = Machine(
{
id: 'lesson',
initial: 'idle',
states: {
...states,
...transientStates,
},
context: {
started: false,
},
},
{
actions: {
start: () => {
throw new Error('Abstract method, needs override');
},
pause: () => {
throw new Error('Abstract method, needs override');
},
resume: () => {
throw new Error('Abstract method, needs override');
},
close: () => {
throw new Error('Abstract method, needs override');
},
complete: () => {
throw new Error('Abstract method, needs override');
},
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment