Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public muteFirst = <T,R>(first$: Observable<T>, second$: Observable<R>) => Observable.combineLatest(
first$,
second$,
(a,b) => b
).distinctUntilChanged();
@mfp22

This comment has been minimized.

Copy link
Owner Author

commented Oct 30, 2017

muteFirst is a helper that joins two levels of dependency together: From the server to the store via first$, and from the store to the component via second$.

@michaeljpeake

This comment has been minimized.

Copy link

commented Apr 18, 2018

If you have something that is triggered by second$ changing, that distinctUntilChanged can be vital. Else, that event will be triggered when first$ emits also.

If you don't want distinctUntilChanged on b but also don't want updates when a changes, I think this is an alternative:

public muteFirst = <T,R>(first$: Observable<T>, second$: Observable<R>) => second$.withLatestFrom(
  first$,
  (b, a) => b
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.