Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 14, 2020 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannwamba/6c1b2e2598090eef1979f3c5e43db054 to your computer and use it in GitHub Desktop.
Save christiannwamba/6c1b2e2598090eef1979f3c5e43db054 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// DEMO: Side effects with activities
// Look for beebing in the console
const initial = "idle";
const states = {
idle: {
on: {
ALARM: "alarming"
}
},
alarming: {
on: {
STOP: "idle"
},
activities: ["beeping"]
}
};
const config = {
id: "alarmClock",
initial,
states
};
const options = {
activities: {
beeping: (context, event) => {
const beep = () => {
console.log("beep");
};
beep();
const intervalId = setInterval(beep, 1000);
return () => clearInterval(intervalId);
}
}
};
const machine = Machine(config, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment