我正在使用ngrx / effects。我想基于foo
商店中的状态调度不同的动作。
这就是我现在正在做的事情:
@Effect() foo1$ = this.updates$
.whenAction(Actions.FOO)
.filter(obj => !obj.state.product.foo)
.map<string>(toPayload)
.map(x => ({ type: Actions.BAR1, payload: { x }}));
@Effect() foo2$ = this.updates$
.whenAction(Actions.FOO)
.filter(obj => obj.state.product.foo)
.map<string>(toPayload)
.map(x => ({ type: Actions.BAR2, payload: { x }}));
有没有办法使用RxJS 5个运营商喜欢的方式partition
,groupBy
,if
,case
在这个岗位?我现在不能正确使用它。
有2个单独的效果源很好。否则,使其变得简单:
@Effect() foo$ = this.updates$
.whenAction(Actions.FOO)
.map(({action, state}) => {
if (state.product.foo) {
return { type: Actions.CHAT_GET_MESSAGES2, payload: { action.payload }};
} else {
return { type: Actions.CHAT_GET_MESSAGES, payload: { action.payload }};
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句