Created
December 27, 2019 11:28
-
-
Save azamara/f3091af109d9f423d02d09b944d69573 to your computer and use it in GitHub Desktop.
Counter Machine
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
const increment = context => context.count + 1; | |
const decrement = context => context.count - 1; | |
const isNotMax = max => context => context.count < max; | |
const isNotMin = min => context => context.count > min; | |
const counterMachine = Machine({ | |
id: "counter", | |
initial: "active", | |
context: { | |
count: 0 | |
}, | |
states: { | |
active: { | |
on: { | |
INC: { | |
actions: assign({ count: increment }) | |
}, | |
DEC: { | |
actions: assign({ count: decrement }) | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment