[英]combine effects in one NgRx
I have similar effects and want to combine it in one but dont know how to do it我有类似的效果,想把它合二为一,但不知道怎么做
Here's my effects (I need to pass different id
depends on action type):这是我的效果(我需要传递不同的
id
取决于动作类型):
setTopics$ = createEffect(
() => this.actions$.pipe(
ofType(setTopics),
map((action) =>
this.service.set(action.payload.id))),
{ dispatch: false });
setHeadlines$ = createEffect(
() => this.actions$.pipe(
ofType(setHeadlines),
map((action) =>
this.service.set(`ldb:${action.payload.id}:0`))),
{ dispatch: false });
I tried to combine actions in ofType
like ofType(setTopics,setHeadlines)
, but how to pass different ids in this.service.set()
我尝试在
ofType
中组合操作,例如ofType(setTopics,setHeadlines)
,但是如何在this.service.set()
中传递不同的 id
Would be really grateful for help!非常感谢您的帮助!
This can be achieved in two ways这可以通过两种方式实现
ldb:<id>:0
in payload as label and setTopics payload will set label same as id( or if you don't want label in setTopics you can check if label exists in effect then use label else id )ldb:<id>:0
设置为 label 和 setTopics 有效负载将设置 label 与 id( 或者如果您不希望 ZD31415888在 setTopics 中,您可以检查 label 是否存在,然后使用 label 否则 id ) if (action.type === actionsType.ACTION1) {
value = action.payload.id
} else if (action.type === actionsType.ACTION2) {
value = `ldb:${action.payload.id}:0`
}
this.service.set(`ldb:${action.payload.id}:0`)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.