Created
April 3, 2020 14:39
-
-
Save ajs139/52ff6622f048b6a8b4050cce3db3d3c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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