Skip to content

Instantly share code, notes, and snippets.

@mikedklein
Created March 6, 2020 03:33
Show Gist options
  • Save mikedklein/92436f4d0af18c594ae4d14229002413 to your computer and use it in GitHub Desktop.
Save mikedklein/92436f4d0af18c594ae4d14229002413 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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