Skip to content

Instantly share code, notes, and snippets.

@timdeschryver
Last active October 16, 2019 18:28
Show Gist options
  • Select an option

  • Save timdeschryver/45ad56fe3879b446eaab5024bc9440b1 to your computer and use it in GitHub Desktop.

Select an option

Save timdeschryver/45ad56fe3879b446eaab5024bc9440b1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const countMachine = Machine(
{
id: "counter",
context: {
counter: 10,
tickSpeed: 1000,
countDiff: 1,
},
initial: "paused",
states: {
counting: {
invoke: {
src: "count$"
},
initial: "up",
states: {
up: {
on: {
DOWN: "down",
TICK: {
actions: "increment"
}
}
},
down: {
on: {
UP: "up",
TICK: {
actions: "decrement"
}
}
}
},
on: {
PAUSE: "paused",
}
},
paused: {
on: {
START: "counting",
}
}
},
on: {
SET_TICK_SPEED: {
actions: "setTickSpeed",
},
SET_COUNT_DIFF: {
actions: "setCountDiff",
cond: 'validCountDiff'
},
SET_COUNT: {
actions: "setCount"
},
RESET: {
actions: "reset"
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment