Skip to content

Instantly share code, notes, and snippets.

@erichulburd
Created December 23, 2017 00:35
Show Gist options
  • Save erichulburd/f47b12709a06ccf0ff10393ca30e8cc5 to your computer and use it in GitHub Desktop.
Save erichulburd/f47b12709a06ccf0ff10393ca30e8cc5 to your computer and use it in GitHub Desktop.
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