Skip to content

Instantly share code, notes, and snippets.

@danabrams
Created August 12, 2020 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danabrams/c352bad2ab46b71e9ea0d16f53a43efa to your computer and use it in GitHub Desktop.
Save danabrams/c352bad2ab46b71e9ea0d16f53a43efa to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const lightSwitchMachine = Machine({
context: { hasPower: true },
id: 'lightSwitch',
initial: 'active',
states: {
active: {
initial: 'turnedOff',
on: {
DEACTIVATE: 'inactive'
},
states: {
turnedOn: {
on: {
SWITCH: 'turnedOff'
},
},
turnedOff: {
on: {
SWITCH: {
target: 'turnedOn',
actions: ['turnOnLight'],
cond: (context, event) => context.hasPower
}
}
}
}
},
inactive: {
on: {
ACTIVATE: 'active',
}
}
},
actions: {
turnOnLight: (context, event) => {
console.log('turning on light...')
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment