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 game = (action$, store) => | |
action$.ofType(actions.START) | |
.mergeMap(() => | |
Observable | |
.interval(250) | |
// ... | |
); |
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 game = (action$, store) => | |
action$.ofType(actions.START) | |
.mergeMap(() => { | |
const interval = Observable.interval(250) | |
.takeUntil(action$.ofType( | |
actions.PAUSE, | |
actions.RESET, | |
actions.END | |
)); | |
}); |
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 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 |
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. |
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 { combineEpics } from 'redux-observable'; | |
//... | |
const applyForce = //... | |
const game = //... | |
export default combineEpics( | |
game, | |
applyForce | |
); |
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 { 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( |
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
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) | |
}) | |
); |
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 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', { |
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
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) | |
}) | |
); |
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
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 |