reactjs - 如何根据条件逻辑触发 RxJS 中的操作?
问题描述
我正在尝试做什么 - 我需要在触发 api 调用(getterFunc)之前添加条件检查,它检查数据是否已经存在于存储中,如果没有,则从后端获取数据。但如果可用,则模拟成功事件并在有效负载中提供存储数据。你能帮我解决我在这个实现中做错了什么吗
const getTemplateEpic = (getterFunc, initial, success, cancel, failure) => (action$, store) => action$.pipe(
ofType(initial),
mergeMap(action => iif(() => Object.keys(store.value.getIn(['whatsApp'].templateListData)).length,
of({
type: success,
payload: { res: store.value.getIn(['whatsApp'].templateListData) }
}),
getterFunc('GET', action.payload)
).pipe(
map(response => ({
type: success,
payload: { res: response.response },
})),
takeUntil(action$.pipe(ofType(cancel))),
catchError(error => of({
type: failure,
payload: { res: error },
})
)
)
)
);
解决方案
推荐阅读
- javascript - 如何在反应打字稿中将输入值从孩子传递给父母
- spring - Spring Boot 开发人员应该知道什么?
- java - kaptGenerateStubs 任务抛出 java.lang.StackOverflowError
- c# - 从 AJAX 返回的部分视图是否可以访问模型参数?
- python - k-means 返回 nan 值?
- javascript - Javascript:通过内部的onclick返回函数增加循环索引
- python - Python:如何将 pyautogui.locateOnScreen 中的左侧或顶部作为 int?
- python - Python创建列表列表
- bash - 在shell脚本中获取目录中的文件列表?
- javascript - JS:检查单词“handover”是否包含“hand”