Skip to content

Instantly share code, notes, and snippets.

@parties
Last active January 25, 2021 22:56
Show Gist options
  • Save parties/c1dd46bacda1b066deca3cbd52c3f4b9 to your computer and use it in GitHub Desktop.
Save parties/c1dd46bacda1b066deca3cbd52c3f4b9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'Fleet Page API',
initial: 'idle',
context: {
dog: null,
schedule: null,
},
states: {
idle: {
on: {
FETCH: 'loading',
FOCUS_REQUIREMENT: 'focused',
CALCULATE: 'calculating',
}
},
// Requirement focused
focused: {
on: {
REASSIGN: 'reassigning',
UNASSIGN: 'unassigning',
}
},
// recalculate fleet schedule
calculating: {
// async pattern here
},
// reassign a requirement to a different vessel
reassigning: {
// async pattern here
},
unassigning: {
// async pattern here
},
loading: {
invoke: {
id: 'fetchDog',
src: (context, event) => fetch('https://dog.ceo/api/breeds/image/random')
.then(data => data.json()),
onDone: {
target: 'resolved',
actions: assign({
dog: (_, 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