Skip to content

Instantly share code, notes, and snippets.

@rthor
Created September 21, 2019 13:52
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 rthor/dfb0da41c8cf55ef62617e1794126aee to your computer and use it in GitHub Desktop.
Save rthor/dfb0da41c8cf55ef62617e1794126aee to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const activeTripMachine = Machine({
id: 'activeTrip',
initial: 'init',
context: {
tripId: null,
pollInterval: 30000,
},
states: {
init: {
exit: ['hasActiveTrip'],
on: {
INIT: 'idle',
},
},
idle: {
on: {
START_TRIP: 'starting',
},
},
starting: {
invoke: {
id: 'startingTrip',
src: 'startTrip',
onDone: {
target: 'active',
actions: assign({
tripId: (_, event) => event.data.id,
}),
},
onError: 'idle',
},
},
stopping: {
invoke: {
id: 'stoppingTrip',
src: 'stopTrip',
onDone: {
target: 'idle',
actions: assign({
tripId: null,
}),
},
onError: 'active',
},
},
active: {
on: {
END_TRIP: 'idle',
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment