Skip to content

Instantly share code, notes, and snippets.

@joemaffei
Last active November 16, 2019 18:35
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 joemaffei/72a6369e3fc0bcd3352303c22e19e01c to your computer and use it in GitHub Desktop.
Save joemaffei/72a6369e3fc0bcd3352303c22e19e01c 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 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