Created
September 15, 2020 19:38
-
-
Save lostinplace/d09f2a8e86efc25d5004dd4bbad47fa1 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
Machine({ | |
id: 'SWAPI', | |
initial: 'idle', | |
context: { | |
user: null | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
loading: { | |
invoke: { | |
id: 'fetchLuke', | |
src: (context, event) => fetch('https://swapi.dev/api/people/1') | |
.then(data => data.json()), | |
onDone: { | |
target: 'resolved', | |
actions: assign({ | |
user: (_, event) => event.data | |
}) | |
}, | |
onError: 'rejected' | |
}, | |
on: { | |
CANCEL: 'idle' | |
} | |
}, | |
resolved: { | |
type: 'final' | |
}, | |
rejected: { | |
on: { | |
FETCH: 'loading' | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment