const reactReduxFirebase = (next) => {
return (reducer, initialState, middleware) => {
const store = next(reducer, initialState, middleware);
store.dispatch({
type:'DUMMY_ACTION'
});
return store;
}< br />}
// 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 Action and console.log them, but it will not capture the’DUMMY_AC’ scheduled by the enhancer TION’, because it is scheduled before saga starts listening (sagaMiddleware.run(sagas);). From the redux-saga documentation, it seems that saga must be run after applyMiddleware, so I cannot run saga before the enhancer. Is there any way to make it work, so the legend will also capture an action from the enhancer?
function* log(action) {
while (true) {
yield take('*');
console.log(action);
}
}
export default function* root() {
yield all([call(log)]);
}
Just to see if it works and then You can try to move to takeEvery, I did have a problem, and create a handle specific to saga work
I need to use store enhancer(reactReduxFirebase , From react-redux-firebase). This enhancer schedules an action, it looks more or less like this (very 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(
applyMiddlewa re(...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 will not capture the’DUMMY_ACTION scheduled by the enhancer ‘Because it is scheduled before saga starts listening (sagaMiddleware.run(sagas);). From the redux-saga documentation, it seems that saga must be run after applyMiddleware, so I cannot run saga before the enhancer. There is What method can make it work, so the legend will also capture an action from the enhancer?
Try this legend
function* log(action) {
while (true) {
yield take('*');
console.log(action);
}
}
export default function* root() {
yield all([call(log)]);
}
Just to see if it works and then you can try to move to takeEvery, I did have a problem And create a handle specific to saga work