Skip to content

Instantly share code, notes, and snippets.

@zerdos
Created October 3, 2020 03:59
Show Gist options
  • Save zerdos/f72bbbc355e1b00ee5f4d420793d9859 to your computer and use it in GitHub Desktop.
Save zerdos/f72bbbc355e1b00ee5f4d420793d9859 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('htts://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