redux-saga - reducer 和 saga 的顺序

标签 redux-saga

当调度一个 Action 时,它到达 reducer 和传奇的顺序是否得到保证?

我可以信赖它

  1. 首先进入reducer
  2. 那么传奇呢?

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 docsselect() 效果 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 calls next(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 calls next(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/

相关文章:

reactjs - createAsyncThunk : dispatch more actions after updating store with fetched data, 在同一有效负载创建者中

reactjs - 如何在刷新访问 token 时暂停和重新启动react-redux应用程序中的API调用?

reactjs - redux-saga中间件如何处理api错误

reactjs - 如何在 redux-saga 中将 url、params、headers 传递给 call() ?

redux-saga 如何监听多个 eventChannel

redux-saga - 我可以使用 return 来停止生成器函数的执行吗?

javascript - 如何在任务管理器回调中使用yield React Native

reactjs - 有什么方法可以将 Saga 与新的 React 钩子(Hook)一起使用?

javascript - Redux Saga 观察者差异

javascript - Redux Saga - 产量生成 takeEvery 调用无过载