Skip to content

Instantly share code, notes, and snippets.

@azamara
Created December 27, 2019 11:28
Show Gist options
  • Save azamara/f3091af109d9f423d02d09b944d69573 to your computer and use it in GitHub Desktop.
Save azamara/f3091af109d9f423d02d09b944d69573 to your computer and use it in GitHub Desktop.
Counter Machine
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