RXJS Pipe中未触发tap() [英] tap() isn't triggered in RXJS Pipe

查看:796
本文介绍了RXJS Pipe中未触发tap()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我更喜欢第一个方法,但我必须采取相同的方法.但是第一种方法似乎行不通. (tap()未触发)

I have to ways of doing the same thing, although I prefer the first one. But the first approach doesn't seem to work. (the tap() is not triggered)

// does not work
this.actions$.pipe(
    ofType(LayoutActions.Types.CHANGE_THEME),
    takeUntil(this.destroyed$),
    tap(() => {
        console.log('test')
    }),
);
// works
this.actions$.ofType(LayoutActions.Types.CHANGE_THEME).subscribe(() => {
    console.log('test')
});

推荐答案

想象一下RxJS管道,就像实际的物理管道,最后是带阀门的.每个管道都会修改"流过的液体,但是只要关闭末端的阀门,就不会有任何流动.

Imagine RxJS pipes like actual, physical pipes with a valve at the end. Each pipe will "modify" the liquid that is flowing through it, but as long as the valve at the end is closed, nothing will ever flow.

因此,您需要的是最后打开阀门.这是通过订阅来完成的.最简单的解决方案是:

So, what you need, is to open the valve at the end. This is done by subscribing to the observable pipe. The easiest solution is:

this.actions$.pipe(
    ofType(LayoutActions.Types.CHANGE_THEME),
    takeUntil(this.destroyed$),
    tap(() => {
        console.log('test')
    }),
).subscribe(_ => console.log("water is flowing!"));

这篇关于RXJS Pipe中未触发tap()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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