Skip to content

Instantly share code, notes, and snippets.

@ecancino
Last active April 26, 2020 06:02
Show Gist options
  • Select an option

  • Save ecancino/def278e5091b3351072d2bd8622b02e5 to your computer and use it in GitHub Desktop.

Select an option

Save ecancino/def278e5091b3351072d2bd8622b02e5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// const { Machine, interpret } = require("xstate");
const lit = {
on: {
BREAK: "broken",
TOGGLE: "unlit"
}
};
const unlit = {
on: {
BREAK: "broken",
TOGGLE: "lit"
}
};
const broken = {
type: "final",
entry: ['logBroken']
};
const states = { lit, unlit, broken };
const initial = "unlit";
const config = {
id: "lightBulb",
strict: true,
initial,
states
};
const lightBulb = Machine(config, {
actions: {
logBroken: (ctx, evt) =>
console.log(`
YO! I am broken in the ${evt.location}
`)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment