gpt4 book ai didi

redux-saga - reducer 和 saga 的顺序

转载 作者:行者123 更新时间:2023-12-03 06:56:03 30 4
gpt4 key购买 nike

当调度一个 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com