Created
July 20, 2018 04:05
-
-
Save ShMcK/81bc7cf0339faab5326521d97eaabc91 to your computer and use it in GitHub Desktop.
xstateful-reducer
This file contains hidden or 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
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