Skip to content

Instantly share code, notes, and snippets.

@jtary
Last active July 9, 2021 15:56
Show Gist options
  • Save jtary/3470be56c3fc9655d3fbc5439c02c661 to your computer and use it in GitHub Desktop.
Save jtary/3470be56c3fc9655d3fbc5439c02c661 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const FS = {
IDLE: 'idle',
OPEN: 'open',
};
actions: ActionFunctionMap = {
showModal: assign({
showModal: (_) => true,
}),
hideModal: assign({
showModal: (_) => false,
newItems: (_) => [],
}),
addItems: assign({
newItems: ({ newItems }, { data }) => [...newItems, ...data],
showModal: (_) => true,
}),
};
/* https://xstate.js.org/viz/?gist=3470be56c3fc9655d3fbc5439c02c661 */
const machine = Machine(
{
initial: FS.IDLE,
context: {
showModal: false,
newItems: [],
},
states: {
[FS.IDLE]: {
on: {
SHOW_MODAL: {
target: FS.OPEN,
actions: 'showModal',
},
ADD_ITEMS: {
target: FS.OPEN,
actions: ['addItems', 'showModal'],
},
},
},
[FS.OPEN]: {
on: {
HIDE_MODAL: {
target: FS.IDLE,
actions: 'hideModal',
},
},
},
},
},
{ actions },
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment