当调度一个 Action 时,它到达 reducer 和传奇的顺序是否得到保证?
我可以信赖它
- 首先进入reducer
- 那么传奇呢?
reducer :
function reducer(state, action) {
switch (action.type) {
case 'MY_ACTION':
// decorate action so that an epic doesn't have to take data from store
action.ports = state.itemsModified;
return state;
}
}
传奇:
export function* sagaUpdatePorts() {
yield* ReduxSaga.takeEvery(actions.GRID_PORTS_ASYNC_UPDATE_PORTS, updatePorts);
}
function* updatePorts(action) {
const {response, error} = yield SagaEffects.call(portsService.updatePorts, action.ports);
}
最佳答案
是的。该操作首先影响 reducer ,然后影响 Sagas。
这是mentioned in the docs在 select()
效果 API 下:
It's important to note that when an action is dispatched to the store, the middleware first forwards the action to the reducers and then notifies the Sagas. This means that when you query the Store's State, you get the State after the action has been applied. However, this behavior is only guaranteed if all subsequent middlewares call
next(action)
synchronously. If any subsequent middleware callsnext(action)
asynchronously (which is unusual but possible), then the sagas will get the state from before the action is applied. Therefore it is recommended to review the source of each subsequent middleware to ensure it callsnext(action)
synchronously, or else ensure that redux-saga is the last middleware in the call chain.
关于redux-saga - reducer 和 saga 的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38607765/