Skip to content

Instantly share code, notes, and snippets.

@yjaaidi
Created April 28, 2022 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjaaidi/56e941683b06a09812b93e837c120c50 to your computer and use it in GitHub Desktop.
Save yjaaidi/56e941683b06a09812b93e837c120c50 to your computer and use it in GitHub Desktop.
RxJS waitLatestForm
import { switchMap } from 'rxjs/operators';
action$;
state$; // facade.country$ etc...
repository$;
fetch$.pipe(withLatestFrom(facade.country$));
waitLatestFrom = (action$) =>
action$.pipe(
switchMap((action) =>
combineLatest(of(action), facade.country$.pipe(take(1)))
)
);
waitLatestFrom = (action$) =>
action$.pipe(concatLatestFrom(() => facade.country$.pipe(take(1))));
fetch$.pipe(
switchMap(
(action) => country$.pipe(take(1)),
map((country) => ({ ...action, country }))
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment