Skip to content

Instantly share code, notes, and snippets.

@tamebadger
Created October 23, 2019 10:09
Show Gist options
  • Save tamebadger/0c05b669d5443adec4d5a8dfdd597735 to your computer and use it in GitHub Desktop.
Save tamebadger/0c05b669d5443adec4d5a8dfdd597735 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const isUndefined = (x) => typeof x === 'undefined';
const flightOpen = ({ flight }) => !isUndefined(flight);
const flightClosed = ({ flight }) => !!isUndefined(flight);
const fetchMachine = Machine({
id: 'flight',
context: { flight: undefined },
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{ target: 'open', cond: flightOpen },
{ target: 'closed', cond: flightClosed }
]
}
},
open: {
on: { CLOSE: { target: 'closed', actions: 'closeFlight' } },
entry: ['notifyActive']
},
closed: {
on: { OPEN: { target: 'open', actions: 'openFlight' } },
entry: ['notifyInactive']
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment