Last active
August 3, 2021 02:25
-
-
Save ddamico/7e35a13188c8a7cb62cfc5dd02f0f16c 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
const multiColoredBulbMachine = Machine({ | |
id: 'multiColoredBulb', | |
initial: 'unlit', | |
context: { | |
color: '#fff' | |
}, | |
states: { | |
lit: { | |
on: { | |
BREAK: 'broken', | |
TOGGLE: 'unlit', | |
CHANGE_COLOR: { | |
actions: ['changeColor'] | |
} | |
} | |
}, | |
unlit: { | |
on: { | |
BREAK: 'broken', | |
TOGGLE: 'lit' | |
} | |
}, | |
broken: { | |
type: 'final' | |
} | |
}, | |
strict: true | |
}, { | |
actions: { | |
changeColor: assign({ | |
color: (context, event) => ({ | |
color: event.color | |
}) | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment