Created
April 7, 2020 18:31
-
-
Save renerbaffa/458037c3dd3e959d6bd205ddd2e9f312 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
function fetchData() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
reject(); | |
}, 1000); | |
}); | |
} | |
const goatMachine = Machine({ | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
CLICK: "loading" | |
} | |
}, | |
loading: { | |
invoke: { | |
src: () => fetchData(), | |
onError: "error", | |
onDone: "idle" | |
} | |
}, | |
error: { | |
on: { | |
CLICK: "loading" | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment