Skip to content

Instantly share code, notes, and snippets.

View erichulburd's full-sized avatar

Eric Hulburd erichulburd

  • Rigetti Computing
  • Berkeley, CA
View GitHub Profile
const game = (action$, store) =>
action$.ofType(actions.START)
.mergeMap(() =>
Observable
.interval(250)
// ...
);
const game = (action$, store) =>
action$.ofType(actions.START)
.mergeMap(() => {
const interval = Observable.interval(250)
.takeUntil(action$.ofType(
actions.PAUSE,
actions.RESET,
actions.END
));
});
const game = (action$, store) =>
action$.ofType(actions.START)
.mergeMap(() => {
const interval = Observable.interval(250)
.takeUntil(action$.ofType(
actions.PAUSE,
actions.RESET,
actions.END
));
const incrementTime = interval
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.
import { combineEpics } from 'redux-observable';
//...
const applyForce = //...
const game = //...
export default combineEpics(
game,
applyForce
);
import { applyForce } from '../';
describe('applyForce epic', () => {
it('throttles and emits apply force if game ongoing', () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
const action$ = new ActionsObservable(
it('throttles and emits apply force if game ongoing', () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
const action$ = new ActionsObservable(
testScheduler.createHotObservable('aaab', {
a: actions.applyForce.click(2),
b: actions.applyForce.click(3)
})
);
import sinon from 'sinon';
// ...
it('throttles and emits apply force if game ongoing', () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
const action$ = new ActionsObservable(
testScheduler.createHotObservable('aaab', {
it('throttles, but does not emit applyForce if game is not ongoing', () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
const action$ = new ActionsObservable(
testScheduler.createHotObservable('aaab', {
a: actions.applyForce.click(2),
b: actions.applyForce.click(3)
})
);
context('game is paused', () => {
it(`interval starts when user starts game and is stopped when end emitted`, () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
const interval$ = testScheduler.createColdObservable('--a--b--c', {
a: 0,
b: 1,
c: 2