Skip to content

Instantly share code, notes, and snippets.

@tamebadger
Created October 25, 2019 10:43
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 tamebadger/55aa422bd1ad7f0093c1ea3b78744d26 to your computer and use it in GitHub Desktop.
Save tamebadger/55aa422bd1ad7f0093c1ea3b78744d26 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const isUndefined = (x) => typeof x === 'undefined';
const flightOpen = ({ flight }) => !isUndefined(flight);
const flightClosed = ({ flight }) => !!isUndefined(flight);
const flight = undefined;
const fetchMachine = Machine({
id: 'flight',
context: { flight, error: undefined },
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{ target: 'open', cond: flightOpen },
{ target: 'closed', cond: flightClosed }
]
}
},
opening: {
invoke: { // https://xstate.js.org/docs/guides/communication.html#invoking-promises
id: 'createFlight',
src: 'createFlight',
onDone: {
target: 'open',
actions: 'assignOpenFlight'
},
onError: {
target: 'failure',
actions: 'assignError'
}
},
entry: ['openMarketplace']
},
open: {
on: {
FLIGHT_DATA_CHANGED: { target: 'closing', actions: 'closeFlight' },
CLOSE: { target: 'closing', actions: 'closeFlight' }
},
entry: ['notifyOpen']
},
closing: {
invoke: { // https://xstate.js.org/docs/guides/communication.html#invoking-promises
id: 'closeFlight',
src: 'closeFlight',
onDone: {
target: 'closed',
actions: 'assignClosedFlight'
},
onError: {
target: 'failure',
actions: 'assignError'
}
},
entry: [ 'closeMarketplace']
},
closed: {
on: {
OPEN: { target: 'opening'},
NO_PREVIOUS_FLIGHT_INFO: { target: 'opening'},
FLIGHT_DATA_CHANGED: { target: 'opening'}
},
entry: ['notifyClose']
},
failure: {
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment