Permalink
Browse files

feat(reduxObservable): allow async streams to emit other async actions,

fixes #8
  • Loading branch information...
jayphelps committed May 14, 2016
1 parent 1486b1f commit 94233f3a5d3afbd6af89ab7bdbcbd08efb1a648a
Showing with 27 additions and 4 deletions.
  1. +1 −1 src/reduxObservable.js
  2. +26 −3 test/reduxObservable-spec.js
@@ -10,7 +10,7 @@ export function reduxObservable() {
return (action) => {
if (typeof action === 'function') {
let obs = from(action(actionsObs, store));
let sub = obs.subscribe(next);
let sub = obs.subscribe(store.dispatch);
return sub;
} else {
actions.next(action);
@@ -127,9 +127,9 @@ describe('reduxObservable', () => {
.delay(10)
.takeUntil(actions.filter(action => action.type === 'ASYNC_ACTION_ABORT'))
.merge(
actions.map(
action => ({ type: action.type + '_MERGED' })
)
actions
.map(action => ({ type: action.type + '_MERGED' }))
.take(1)
)
.startWith({ type: 'ASYNC_ACTION_1' })
);
@@ -147,4 +147,27 @@ describe('reduxObservable', () => {
done();
}, 100);
});
it('should store.dispatch onNext to allow async actions to emit other async actions', (done) => {
const reducer = (state = [], action) => state.concat(action);
const middleware = reduxObservable();
const store = createStore(reducer, applyMiddleware(middleware));
const action2 = (actions) => Observable.of({ type: 'ASYNC_ACTION_2' });
const action1 = (actions) => Observable.of({ type: 'ASYNC_ACTION_1' }, action2);
store.dispatch(action1);
// HACKY: but should work until we use TestScheduler.
setTimeout(() => {
expect(store.getState()).to.deep.equal([
{ type: '@@redux/INIT' },
{ type: 'ASYNC_ACTION_1' },
{ type: 'ASYNC_ACTION_2' }
]);
done();
}, 100);
});
});

0 comments on commit 94233f3

Please sign in to comment.