Created
July 30, 2019 02:09
-
-
Save isaacplmann/396666f4a465ebe1f6f2ea464fb9e917 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
const selectionMachine = Machine( | |
{ | |
id: 'selection', | |
context: { | |
selectedIndex: undefined, | |
}, | |
initial: 'unselected', | |
states: { | |
unselected: { | |
on: { | |
SELECT: 'selected', | |
} | |
}, | |
selected: { | |
onEntry: [assign((ctx, event) => ({ | |
selectedIndex: event.selectedIndex | |
})), | |
sendParent((ctx) => ({ | |
type: 'SUBMIT', | |
selectedIndex: ctx.selectedIndex | |
})) | |
] | |
} | |
} | |
} | |
); | |
const matchingMachine = Machine( | |
{ | |
id: 'matching', | |
context: { | |
choiceOneRef: null, | |
choiceTwoRef: null | |
}, | |
initial: 'answering', | |
states: { | |
answering: { | |
entry: assign({ | |
choiceOneRef: () => spawn(selectionMachine), | |
choiceTwoRef: () => spawn(selectionMachine) | |
}), | |
on: { | |
CHOOSE_ONE: { | |
actions: send('SELECT', { | |
to: ctx => ctx.choiceOneRef | |
}) | |
}, | |
CHOOSE_TWO: { | |
actions: send('SELECT', { | |
to: ctx => ctx.choiceTwoRef | |
}) | |
}, | |
SUBMIT: 'submitted', | |
} | |
}, | |
submitted: { | |
on: { | |
CLEAR: 'answering' | |
} | |
} | |
} | |
}, | |
{} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment