【发布时间】:2023-11-13 20:13:01
【问题描述】:
我希望能够通过 redux 从应用程序的不同部分调用两组操作。但是,我想以正确的顺序运行它们,并确保 set b 永远不会在 set a 之前运行。
例如,假设我有两个操作,configure 和 execute。我需要确保execute 永远不会在configure 之前运行,但它们可能会被乱序调度。在这种情况下,我需要将 execute 加入队列,并且仅在 configure 完成后处理。
这可以在 redux-saga 中做到吗?
我尝试了以下方法,似乎根本没有阻塞:
function* configureSaga({ payload }): IterableIterator<any> {
yield put(aFirstThing(payload));
yield put(aSecondThing());
}
function* executeSaga({ payload }): IterableIterator<any> {
yield put(aThirdThing(payload));
yield put(aFourthThing());
}
export function* adsSaga(): IterableIterator<any> {
const configureChanel = yield actionChannel({ type: 'configure' });
yield takeEvery(configureChanel, configureSaga);
yield takeEvery({ type: 'execute' }), executeSaga);
}
按照以下顺序给定两个调度:
dispatch({ type: 'execute' })
dispatch({ type: 'configure' })
我需要按该顺序执行的aFirstThing, aSecondThing, aThirdThing, aFourthThing 操作。
redux-sagas 可以做到这一点吗?
【问题讨论】:
标签: reactjs redux react-redux redux-saga