Last active
November 16, 2019 18:35
-
-
Save joemaffei/72a6369e3fc0bcd3352303c22e19e01c 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const scopes = { | |
INTERNATIONAL: 'international', | |
DOMESTIC: 'domestic' | |
}; | |
const mots = { | |
OCEAN: 'ocean', | |
GROUND: 'ground', | |
AIR: 'air' | |
}; | |
function setScope(ctx, e) { | |
ctx.scope = scopes[e.type]; | |
}; | |
function setInternational(ctx) { | |
ctx.scope = scopes.INTERNATIONAL | |
} | |
function setMot(ctx, e) { | |
ctx.mot = mots[e.type]; | |
}; | |
const quoteMachine = Machine({ | |
id: 'quote', | |
initial: 'welcome', | |
context: { | |
scope: '', | |
mot: '' | |
}, | |
states: { | |
welcome: { | |
on: { | |
INTERNATIONAL: { | |
target: '#mot', | |
actions: setInternational | |
}, | |
DOMESTIC: { | |
target: '#mot', | |
actions: setScope | |
} | |
} | |
}, | |
mot: { | |
id: 'mot', | |
intial: 'unknown', | |
states: { | |
unknown: { | |
on: { | |
'': [{ | |
target: 'international', | |
cond: 'isInternational' | |
}, { | |
target: 'domestic', | |
cond: 'isDomestic' | |
}] | |
} | |
}, | |
international: { | |
on: { | |
OCEAN: { | |
target: '#map.international', | |
actions: setMot | |
}, | |
AIR: { | |
target: '#map.international', | |
actions: setMot | |
} | |
} | |
}, | |
domestic: { | |
on: { | |
GROUND: { | |
target: '#map.domestic', | |
actions: setMot | |
}, | |
AIR: { | |
target: '#map.domestic', | |
actions: setMot | |
} | |
} | |
} | |
} | |
}, | |
map: { | |
id: 'map', | |
states: { | |
international: {}, | |
domestic: {} | |
}, | |
on: { | |
NEXT: '#dates' | |
} | |
}, | |
dates: { | |
id: 'dates', | |
on: { | |
NEXT: { | |
target: '#option' | |
} | |
} | |
}, | |
option: { | |
id: 'option' | |
} | |
} | |
}, { | |
guards: { | |
isInternational: (ctx) => { | |
ctx.scope === scopes.INTERNATIONAL | |
}, | |
isDomestic: (ctx) => { | |
ctx.scope === scopes.DOMESTIC | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment