Skip to content

Instantly share code, notes, and snippets.

@mfp22
Created October 27, 2017 15:35
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfp22/be6f34dacf66c06eca4daa32039e914e to your computer and use it in GitHub Desktop.
Save mfp22/be6f34dacf66c06eca4daa32039e914e to your computer and use it in GitHub Desktop.
public muteFirst = <T,R>(first$: Observable<T>, second$: Observable<R>) => Observable.combineLatest(
first$,
second$,
(a,b) => b
).distinctUntilChanged();
@mfp22
Copy link
Author

mfp22 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
Copy link

michaeljpeake 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