Created
November 16, 2020 14:56
-
-
Save rreckonerr/a75bb6aade13ac29d40e93ebb6baec13 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 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