Skip to content

Instantly share code, notes, and snippets.

@lettertwo
Created January 6, 2021 18:59
Show Gist options
  • Save lettertwo/d6100571bf73a7f47ca80fcbee72247f to your computer and use it in GitHub Desktop.
Save lettertwo/d6100571bf73a7f47ca80fcbee72247f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const createTicketQuantityMachine = (max = 19) => Machine({
context: {count: 0},
initial: 'idle',
states: {
idle: {
on: {
INCREMENT: {
actions: 'increment',
cond: 'canIncrement'
},
DECREMENT: {
actions: 'decrement',
cond: 'canDecrement'
}
}
}
}}, {
actions: {
increment: assign({
count: (context) => context.count + 1
}),
decrement: assign({
count: (context) => context.count - 1
}),
},
guards: {
canIncrement: (context) => context.count < max,
canDecrement: (context) => context.count > 0,
}
});
const quantityMachine = createTicketQuantityMachine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment