Skip to content

Instantly share code, notes, and snippets.

@haishanh
Created May 2, 2020 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haishanh/a2a291670156e1c12039491478529a62 to your computer and use it in GitHub Desktop.
Save haishanh/a2a291670156e1c12039491478529a62 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'SWAPI',
initial: 'idle',
context: {
user: null
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
invoke: {
id: 'fetchLuke',
src: (context, event) => fetch('https://swapi.co/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