我最近升级到redux-saga v。0.16.0,似乎由saga通过put
调度的动作没有立即传递到reducer。因此,我的传奇确实多次请求http。我已经阅读了日志,调试显示出put动作是捆绑在一起并分派的,但是为时已晚。
知道我在做什么错吗?
这里有一些伪代码与生产中的伪代码几乎相同。
const shouldFetchApplications = (state, userId) => {
return !state.applications[userId].fetched
&& !state.applications[userId].fetching;
}
export function* fetchApplications(action) {
const userId = action.userId;
const shouldFetch = yield select(shouldFetchApplications, userId);
if (shouldFetch) {
yield put(actions.isFetchingApplications(userId));
try {
const data = yield call(get, `/applications?userId=${userId}`);
yield put(actions.applicationsFetched(data, userId));
} catch (e) {
console.log(e);
yield put(actions.fetchFailed(userId));
}
}
}
function* watchFetchApplications() {
yield takeEvery(actiontypes.FETCH_APPLICATIONS_REQUESTED, fetchApplications);
}
export default function* applicationSagas() {
yield fork(watchFetchApplications);
}