Redux 重演传奇,将同一个动作并行多次
我怎样才能将相同的动作类型并行地放置多次,并且能够获得所有的响应?在Redux的文档中,他们使用Redux 重演传奇,将同一个动作并行多次,redux,react-redux,Redux,React Redux,我怎样才能将相同的动作类型并行地放置多次,并且能够获得所有的响应?在Redux的文档中,他们使用call和all并行地进行API调用,但从我所读的内容来看,只有在调度操作时才会调用减缩器。如何并行调度同一个操作,获取每个操作的结果,并调用减缩器 # api/actions.ts const getUserRequest = createAction('GET_USER_REQUEST', { userId }); const getUserSuccess = createAction('GET_
call
和all
并行地进行API调用,但从我所读的内容来看,只有在调度操作时才会调用减缩器。如何并行调度同一个操作,获取每个操作的结果,并调用减缩器
# api/actions.ts
const getUserRequest = createAction('GET_USER_REQUEST', { userId });
const getUserSuccess = createAction('GET_USER_SUCCESS', { user });
# api/sagas.ts
function* fetchUser(action) {
const user = axios.get(`api.example.com/users/${action.payload.userId}`;
yield put({type: GET_USER_SUCCESS, user.data});
}
# api/reducers.ts
function (state, action) {
switch(action.type) {
case: GET_USER_REQUEST:
return {
...state,
[action.payload.userId] = {}
};
case: GET_USER_SUCCESS:
return {
...state,
[action.payload.userId] = {...action.payload}
};
default:
return state;
}
}
# ui/sagas.ts
function* fetchSelectedUsers(userIds: number[]){
# I'm stuck at this saga. How can I get multiple users, have reducers invoked, and perform additional processing in this saga after they've been retrieved?
const actionsToDispatch = userIds.map(x =>
put(getUserRequest({userId}))
);
yield all(actionsToDispatch);
# Pseudo code
const users = yield take(actionsToDispatch);
users.map(x => {
// Perform additional work from users that were returned. Reducers must also be called from the `yield all(actionsToDispatch);` from above.
});
}
你好,迈克,你找到解决办法了吗?你好,迈克,你找到解决办法了吗?