Skip to content

Instantly share code, notes, and snippets.

@rreckonerr
Created November 16, 2020 14:56
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 rreckonerr/a75bb6aade13ac29d40e93ebb6baec13 to your computer and use it in GitHub Desktop.
Save rreckonerr/a75bb6aade13ac29d40e93ebb6baec13 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 items = [
{
id: 1,
type: "one"
},
{
id: 2,
type: "two"
},
{
id: 3,
type: "three"
}
]
const itemOneMachine = Machine({
id: "item",
initial: 'initial',
context: {},
states: {
initial: {
actions: sendParent({
type: 'TRANSITION_TO',
target: 'modal-3'
}),
},
}
})
const modalMachine = Machine({
id: 'modal',
initial: 'modal-1',
context: {},
states: {
'modal-1': {
on: {
SELECT_ITEM: {
actions: assign({
itemRef: (context, event) => {
return spawn(itemOneMachine, 'item')
}
})
},
TRANSITION_TO: [
{
target: 'modal-2',
cond: (context, event) => {
return event.target === 'modal-2'
}
},
{
target: 'modal-3',
cond: (context, event) => {
return event.target === 'modal-3'
}
}
]
}
},
'modal-2': {},
'modal-3': {}
}
});
interpret(modalMachine).send('SELECT_ITEM');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment