Created
December 23, 2017 00:35
-
-
Save erichulburd/f47b12709a06ccf0ff10393ca30e8cc5 to your computer and use it in GitHub Desktop.
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
const applyForce = (action$, store) => | |
action$.ofType(actions.APPLY_FORCE_CLICK) | |
.throttleTime(100) | |
// Do not apply force unless game is ongoing. | |
.filter(_action => selectors.isGameOngoing(store.getState())) | |
.map(action => actions.applyForce(action.payload)); | |
const game = (action$, store) => | |
action$.ofType(actions.START_CLICK) | |
// Do not start game if it is already ongoing. | |
.filter(action => !selectors.isGameOngoing(store.getState())) | |
.mergeMap(() => { | |
const start = Observable.of(actions.start()); | |
const interval = Observable.interval(250) | |
.takeUntil(action$.ofType( | |
actions.PAUSE, | |
actions.RESET, | |
actions.END | |
)); | |
const incrementTime = interval | |
.map(_interval => actions.incrementTime()); | |
const end = interval | |
// Only end game if the user has lost. | |
.filter(_action => selectors.shouldGameEnd(store.getState())) | |
.map(_action => actions.end()); | |
return Observable.merge(start, incrementTime, end); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment