如何在ngrx/effects中使用/其他? [英] How to do if/else in ngrx/effects?

查看:62
本文介绍了如何在ngrx/effects中使用/其他?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ngrx/effects.我想基于商店中的foo状态调度不同的操作.

I am using ngrx/effects. I want to dispatch different actions based on a foo state in the store.

这是我现在正在做的事情:

This is how I am doing now:

 @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 }}));

是否可以使用

Is there a way to use RxJS 5 operators like partition, groupBy, if, case in this post? I cannot use it correctly now.

推荐答案

具有2个单独的效果源就可以了.否则就简单点:

Having 2 separate effect sources are fine. Otherwise make it simple:

@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 }};
        }
    });

这篇关于如何在ngrx/effects中使用/其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆