tap() isn't triggered in RXJS Pipe

后端 未结 2 1239
灰色年华
灰色年华 2020-12-11 15:10

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)



        
2条回答
  •  长情又很酷
    2020-12-11 16:11

    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!"));
    

提交回复
热议问题