Created
March 5, 2020 14:36
-
-
Save mapicard/5fffe20e2772d10289faf5070d65c870 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 increment = context => context.count + 1; | |
const decrement = context => context.count - 1; | |
const counterMachine = Machine({ | |
initial: 'active', | |
context: { | |
count: 0 | |
}, | |
states: { | |
active: { | |
on: { | |
INC: { actions: assign({ count: increment }) }, | |
DEC: { actions: assign({ count: decrement }) } | |
} | |
} | |
} | |
}); | |
const counterService = interpret(counterMachine) | |
.onTransition(state => console.log(state.context.count)) | |
.start(); | |
// => 0 | |
counterService.send('INC'); | |
// => 1 | |
counterService.send('INC'); | |
// => 2 | |
counterService.send('DEC'); | |
// => 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment