Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Created July 20, 2018 04:05
Show Gist options
  • Save ShMcK/81bc7cf0339faab5326521d97eaabc91 to your computer and use it in GitHub Desktop.
Save ShMcK/81bc7cf0339faab5326521d97eaabc91 to your computer and use it in GitHub Desktop.
xstateful-reducer
import { createStatefulMachine, Reducer } from '@avaragado/xstateful'
import alarmMachine from './alarmMachine'
const initialState = {
alarmTrigger: +new Date() + 10000
}
const reducer = Reducer.map({
alarmSet: Reducer.update(({ action, extstate }) => ({
alarmTrigger: action.time,
}),
snooze: Reducer.update(({ action, extstate }) => ({
alarmTrigger: extstate.alarmTrigger + (10 * 60)
}),
startRing: Reducer.update(({ action, exstate }) => ({
ringCount: exstate.ringCount + 1,
})
})
const AlarmMachine = createStatefulMachine({
machine: alarmMachine,
extstate: initialState,
reducer,
})
export default AlarmMachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment