Skip to content

Instantly share code, notes, and snippets.

@yinonov
Last active February 11, 2019 09:38
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 yinonov/315cdc033d39f2ef651f767c686ce73b to your computer and use it in GitHub Desktop.
Save yinonov/315cdc033d39f2ef651f767c686ce73b to your computer and use it in GitHub Desktop.
code example for preserving cart state article
cartChange$ = this.cartForm.valueChanges.pipe(
skipUntil(this.onLoad$.pipe(last())), // wait until onLoad$ is done
withLatestFrom(this.auth.user$),
switchMap(([cart, user]) => !!user ?
saveCartToDb$(cart) : // switch to saving to database observable
saveCartToStorage$(cart)) // switch to saving to storage observable
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment