Created
August 12, 2020 18:29
-
-
Save danabrams/c352bad2ab46b71e9ea0d16f53a43efa 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 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