manaflair / redux-batch

Enhance your Redux store to support batched actions
171 stars 12 forks source link

Subscribers are not called for async actions #4

Closed arcanis closed 7 years ago

arcanis commented 7 years ago

It seems I've successfully reproduced the bug described in #1. Testcase:

let { reduxBatch }                            = require('./');
let { put, takeEvery }                        = require('redux-saga/effects');
let createSagaMiddleware                      = require('redux-saga').default;
let { applyMiddleware, compose, createStore } = require('redux');

let reducer = (state = {}) => state;

let sagaMiddleware = createSagaMiddleware();
let store = createStore(reducer, compose(reduxBatch, applyMiddleware(sagaMiddleware), reduxBatch));

sagaMiddleware.run(function* () {
    yield takeEvery(`42`, function* (action) {
        yield put([ { type: `666` }, { type: `666` } ]);
        yield new Promise(resolve => setTimeout(resolve, 1000));
        yield put([ { type: `666` }, { type: `666` } ]);
        console.log(`yada`);
    });
});

store.subscribe(() => {
    console.log(`subscriptors called!`);
});

console.log(`start`);
store.dispatch({ type: `42` });
console.log(`stop`);

It should print:

start
subscriptors called!
stop
yada
subscriptors called!

Unfortunately, it prints:

start
subscriptors called!
stop
yada
arcanis commented 7 years ago

Should be fixed with 274c2ca