Created
November 21, 2019 18:50
-
-
Save steveruizok/912eed00d35462491ad8b70d566c5959 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
const isNotMax = context => context.count < 10; | |
const isNotMin = context => context.count > 0; | |
const increment = context => context.count + 1; | |
const decrement = context => context.count - 1; | |
const counterMachine = Machine({ | |
initial: 'active', | |
context: { | |
count: 0 | |
}, | |
states: { | |
inactive: { | |
on: { | |
TURN_ON: "active" | |
} | |
}, | |
active: { | |
on: { | |
TURN_OFF: "inactive", | |
INCREMENT: { | |
actions: assign({ count: increment }), | |
cond: isNotMax | |
}, | |
DECREMENT: { | |
actions: assign({ count: decrement }), | |
cond: isNotMin | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment