Created
May 4, 2020 22:08
-
-
Save brookslybrand/2a8c804455aea23bbe4aa319b2b38baf to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 autoSaveMachine = Machine( | |
{ | |
id: 'autoSaveMachine', | |
initial: 'saved', | |
states: { | |
saved: { | |
on: { | |
HAS_UNSAVED_DATA: 'waitingToSave' | |
} | |
}, | |
waitingToSave: { | |
after: [ | |
{ | |
delay: 1000, | |
target: 'readyToSave' | |
} | |
] | |
}, | |
readyToSave: { | |
on: { | |
SAVE_DATA: 'saving' | |
} | |
}, | |
saving: { | |
invoke: { | |
src: 'uploadData', | |
onDone: 'saved', | |
onError: 'error' | |
} | |
}, | |
error: { | |
on: { | |
RETRY: 'readyToSave' | |
} | |
} | |
} | |
}, | |
{ | |
services: { | |
uploadData: (ctx, e) => { | |
return Math.random() < 0.2 ? Promise.reject() : Promise.resolve() | |
} | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment