Last active
October 22, 2021 22:16
-
-
Save joeshub/fb791a0dc414502f8c30bec21fb03a5f 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 lit = { | |
on: { | |
BREAK: { | |
// target: 'broken', | |
actions: send({type: 'TOGGLE'}) | |
}, | |
TOGGLE: 'unlit' | |
} | |
} | |
const unlit = { | |
on: { | |
BREAK: 'broken', | |
TOGGLE: 'lit', | |
CHANGE_COLOR: { | |
actions: assign({ | |
color: (ctx, evt) => evt.color | |
}) | |
} | |
} | |
} | |
// what is type? | |
const broken = { | |
type: 'final' | |
} | |
const states = { lit, unlit, broken } | |
const initial = 'unlit' | |
const config = { | |
id: 'lightBulb', | |
context: { | |
color: "#fff" | |
}, | |
initial, | |
states, | |
strict: true | |
} | |
const options = { | |
actions: { | |
logBroken: (ctx, event) => {console.log(`ACTION: I am broken in ${event.location}`)}, | |
changeColor: () => { | |
assign({ | |
color: '#f0f' | |
}) | |
} | |
} | |
} | |
const fetchMachine = Machine(config, options); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment