如何在一部史诗中处理多种动作类型?这样做有什么坏处吗?
How to handle multiple action types in one epic? Any cons of doing the same?
redux-observables、rxjs 和 observables 的新手。想知道如何处理另一个动作,比如在同一史诗
中说 'ActionTwo'
const Epic1 = (action$,store) => {
return action$.ofType('ActionOne')
.mergeMap((action) => {
return ajax({'method': 'GET', 'url': 'someUrl')
.map(response => resultActoin(action.userId, response.response));
}
);
}
类似
const Epic1 = (action$){
if('ActionOne') make a API call.
if('ActionTwo') make some other API call.
else do nothing.
}
是同一个API电话吗?如果是这样,ofType()
接受不止一种类型。你可以做 action$.ofType('ActionOne', 'ActionTwo')
.
如果你想向另一个人提出要求API/URL,我建议你再制作一个史诗。您可以 "merge" 所有 epics 和 combineEpics
参见:https://redux-observable.js.org/docs/basics/SettingUpTheMiddleware.html
redux-observables、rxjs 和 observables 的新手。想知道如何处理另一个动作,比如在同一史诗
中说 'ActionTwo'const Epic1 = (action$,store) => {
return action$.ofType('ActionOne')
.mergeMap((action) => {
return ajax({'method': 'GET', 'url': 'someUrl')
.map(response => resultActoin(action.userId, response.response));
}
);
}
类似
const Epic1 = (action$){
if('ActionOne') make a API call.
if('ActionTwo') make some other API call.
else do nothing.
}
是同一个API电话吗?如果是这样,ofType()
接受不止一种类型。你可以做 action$.ofType('ActionOne', 'ActionTwo')
.
如果你想向另一个人提出要求API/URL,我建议你再制作一个史诗。您可以 "merge" 所有 epics 和 combineEpics
参见:https://redux-observable.js.org/docs/basics/SettingUpTheMiddleware.html