Skip to content

Instantly share code, notes, and snippets.

@QMaximillian
Last active May 2, 2020 20:04
Show Gist options
  • Save QMaximillian/5c4c73a0a76cb3edc6b16c2ff4e35815 to your computer and use it in GitHub Desktop.
Save QMaximillian/5c4c73a0a76cb3edc6b16c2ff4e35815 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 lightBulbMachine = Machine({
id: 'lightBulbMachine',
initial: 'unlit',
context: {
color: "#fff"
},
states: {
unlit: {
on: {
TOGGLE: 'lit',
BREAK: {
target: 'broken',
// actions: () => console.log('transitioning')
},
},
},
lit: {
exit: [() => console.log('it is growing dark and cold'),() => console.log('very...cold')],
on: {
TOGGLE: 'unlit',
BREAK: {
target: 'broken',
actions: () => { console.log('transitioning to broken')
},
},
CHANGE_COLOR: {
actions: assign({
color: (context, event) => event.color
})
}
}
},
broken: {
type: 'final',
entry: ['logLocation', 'buyANewBulb']
},
},
on: {
DO_NOTHING: {type: '.lit', actions: () => console.log("i'm lit")},
}
}, {
actions: {
logLocation: (context, event) => { console.log(event.location)}
}
,
buyANewBulb: () => console.log('Buy a new bulb')
});
// const idleMachine = Machine({
// id: 'idle',
// initial: 'idle',
// states: {
// idle: {
// entry: 'logEntry',
// exit: 'logExit',
// }
// },
// on: {
// DO_NOTHING: '.idle'
// }
// }, {
// actions: {
// logEntry: () => console.log('entered'),
// logExit: () => console.log('exited')
// }
// })
// const echoMachine = Machine({
// id: 'echo',
// initial: 'listening',
// states: {
// listening: {
// on: {
// SPEAK: {
// actions: send({type: 'ECHO'})
// },
// ECHO: {
// actions: () => console.log('echo echo')
// }
// },
// }
// },
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment