Skip to content

Instantly share code, notes, and snippets.

@ZempTime
Created September 18, 2019 21:02
Show Gist options
  • Save ZempTime/ee5e0c015a4697325367a2b9053ffb94 to your computer and use it in GitHub Desktop.
Save ZempTime/ee5e0c015a4697325367a2b9053ffb94 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine(
{
id: 'multiply',
initial: 'addThenMultiply',
states: {
addThenMultiply: {
on: {
TOGGLE: 'multiplyThenAdd',
INCREMENT: {
actions: ['multiply', 'add'],
},
},
},
multiplyThenAdd: {
on: {
TOGGLE: 'addThenMultiply',
INCREMENT: {
actions: ['add', 'multiply'],
},
},
},
},
on: {
RESET: {
actions: 'reset',
},
CHANGE_VALUE: {
actions: 'setValue',
},
},
},
{
actions: {
add: assign({ count: context => context.count + 1 }),
multiply: assign({ count: context => context.count * context.value }),
reset: assign({ count: 3 }),
setValue: assign({ value: (_context, event) => event.value }),
},
},
{ count: 3, value: 2 },
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment