Created
March 6, 2020 03:33
-
-
Save mikedklein/92436f4d0af18c594ae4d14229002413 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
// Action to increment the context amount | |
const incrementCount = assign({ | |
count: (context, _) => context.count + 1 | |
}); | |
const lightBulbMachine = Machine( | |
{ | |
id: 'lightBulb', | |
initial: 'unlit', | |
context: { | |
count: 0 | |
}, | |
states: { | |
lit: { | |
on: { | |
BREAK: 'broken', | |
TOGGLE: { | |
target: 'unlit', | |
actions: 'incrementCount' | |
} | |
} | |
}, | |
unlit: { | |
on: { | |
BREAK: 'broken', | |
TOGGLE: { | |
target: 'lit', | |
actions: 'incrementCount' | |
} | |
} | |
}, | |
broken: { | |
on: { | |
BREAK: { | |
target: 'lit', | |
actions: 'incrementCount' | |
} | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
incrementCount | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment