Skip to content

Instantly share code, notes, and snippets.

Eric Hulburd erichulburd

  • UC Berkeley
  • Berkeley, CA
Block or report user

Report or block erichulburd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tests8.js
// ...
it('does not restart game when ongoing and emits end event when user loses', () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
const interval$ = testScheduler.createColdObservable('--a--b', {
a: 0,
a: 1
View tests7.js
context('user will lose', () => {
afterEach(() => {
Observable.interval.restore();
});
it('does not restart game when ongoing and emits end event when user loses', () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
View tests6.js
context('game is paused', () => {
afterEach(() => {
Observable.interval.restore();
});
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);
});
View tests5.js
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
View tests4.js
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)
})
);
View tests3.js
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', {
View tests2.js
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)
})
);
View tests1.js
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(
View epics6.js
import { combineEpics } from 'redux-observable';
//...
const applyForce = //...
const game = //...
export default combineEpics(
game,
applyForce
);
View epics5.js
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.
You can’t perform that action at this time.