Created
January 6, 2021 18:59
-
-
Save lettertwo/d6100571bf73a7f47ca80fcbee72247f 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
// 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