I need to use store enhancer (reactReduxFirebase from react-redux-firebase) in my redux app. This enhancer dispatches an action, it looks more or less like this (much simplified):
const reactReduxFirebase = (next) => {
return (reducer, initialState, middleware) => {
const store = next(reducer, initialState, middleware);
store.dispatch({
type: 'DUMMY_ACTION'
});
return store;
}
}
// usage
const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];
const store = createStore(
reducer,
initialState,
compose(
applyMiddleware(...middleware),
reactReduxFirebase
)
);
sagaMiddleware.run(sagas);
// sagas.js
function* handle(action) {
console.log(action);
}
function* saga() {
yield takeEvery('*', handle);
}
export default saga;
I want saga to listen to all actions and console.log them, but it doesn't catch 'DUMMY_ACTION' dispatched by enhancer, because it's being dispatched before saga starts to listen (sagaMiddleware.run(sagas);
). From redux-saga docs it seems that saga must be run after applyMiddleware, so I cannot make saga run before enhancer. Is there any way to make it work, so the saga will catch an action from enhancer as well?
The solution based on
applyMiddlware
:The log:
try this for sagas
just to see if it works then you can try moving to takeEvery, I did have issues with it and creating handles specific to saga worked