Created
May 14, 2020 17:47
-
-
Save christiannwamba/6c1b2e2598090eef1979f3c5e43db054 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
// 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