Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Last active July 22, 2018 15:27
Show Gist options
  • Save ShMcK/769a179f89f1d7db1f83363cc2e42399 to your computer and use it in GitHub Desktop.
Save ShMcK/769a179f89f1d7db1f83363cc2e42399 to your computer and use it in GitHub Desktop.
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