Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Last active Jul 22, 2018
Embed
What would you like to do?
xstate example
import { Machine } from 'xstate'
const Alarm = {
Alarm: {
initial: 'Ringing',
on: { CANCEL: 'Idle' },
states: {
Ringing: {
on: { SNOOZE: 'Snoozing' },
onEntry: ['startRing'],
onExit: ['stopRing'],
},
Snoozing: {
on: { ALARM_TRIGGED: 'Ringing' },
onEntry: ['snoozeTimer'],
},
}
}
}
const alarmClock = Machine({
initial: 'Idle',
states: {
Idle: {
on: { ALARM_TRIGGERED: 'Ringing' }
},
...Alarm,
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment