Created
October 25, 2019 10:43
-
-
Save tamebadger/55aa422bd1ad7f0093c1ea3b78744d26 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 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