Created
September 21, 2019 23:42
-
-
Save rthor/ff280132f2608fee2fe314fe8075aa9a 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
const activeTripMachine = Machine({ | |
id: 'activeTrip', | |
initial: 'init', | |
context: { | |
trip: null, | |
lastTrip: null, | |
pollInterval: 15000, | |
}, | |
states: { | |
init: { | |
exit: ['hasActiveTrip'], | |
on: { | |
NEXT: 'idle', | |
}, | |
}, | |
idle: { | |
on: { | |
START_TRIP: 'starting', | |
RESTART: 'active', | |
SERVER_STOP: 'stoppedByServer', | |
}, | |
}, | |
starting: { | |
invoke: { | |
id: 'startingTrip', | |
src: 'startTrip', | |
onDone: { | |
target: 'active', | |
actions: assign({ | |
trip: (_, event) => event.data, | |
}), | |
}, | |
onError: 'idle', | |
}, | |
}, | |
stopping: { | |
invoke: { | |
id: 'stoppingTrip', | |
src: 'stopTrip', | |
onDone: 'ended', | |
onError: 'active', | |
}, | |
}, | |
stoppedByServer: { | |
onEntry: assign({ | |
lastTrip: (_, { lastTrip }) => lastTrip, | |
}), | |
on: { | |
NEXT: 'ended', | |
}, | |
}, | |
ended: { | |
onEntry: assign({ | |
trip: () => null, | |
}), | |
on: { | |
NEXT: 'idle', | |
}, | |
}, | |
active: { | |
activities: ['polling'], | |
on: { | |
END_TRIP: 'stopping', | |
SERVER_STOP: 'stoppedByServer', | |
STOP_POLLING: 'init', | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment