Skip to content

Instantly share code, notes, and snippets.

View yinonov's full-sized avatar
:octocat:
I may be slow to respond

yinon yinonov

:octocat:
I may be slow to respond
View GitHub Profile
onLoad$ = return this.auth.user$.pipe(
take(1), // we only do this once as we only want to handle the initial load
...
);
@yinonov
yinonov / on load observable
Created February 11, 2019 09:29
code example for preserving cart state article
onLoad$ = return this.auth.user$.pipe(
take(1), // we only do this once as we only want to handle the initial load
...
);
@yinonov
yinonov / on load observable 2
Created February 11, 2019 09:34
code example for preserving cart state article
onLoad$ = this.auth.user$.pipe(
take(1), // we only do this once as we only want to handle the initial load
switchMap(user => !!user ? mergedCartStates$ : cartStateFromStorage$),
// set the cart form with the retrieved state's value
tap(setCartValue) // set the cart's form with emitted value
);
@yinonov
yinonov / cart change observable
Last active February 11, 2019 09:38
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
);
@yinonov
yinonov / cart reset observable
Created February 11, 2019 09:39
code example for preserving cart state article
userChange$ = this.auth.user$.pipe(
skip(1), // skip the initial emit to let the onLoad$ do its verification first
);
cartReset$ = this.userChange$.pipe(
filter((user: User) => !user),
tap(() => this.setCartValue({ cartItems: [] })),
);
@yinonov
yinonov / the single subscription
Created February 11, 2019 09:42
code example for preserving cart state article
const subscription = merge(
this.cartChange$,
this.cartReset$
).subscribe();
@yinonov
yinonov / machine.js
Last active January 7, 2020 16:40
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@yinonov
yinonov / index.html
Last active November 27, 2020 07:03
Vivid "short" - Autocomplete
<div style="position: relative;">
<vwc-textfield
id="textfield"
outlined
list="menu"
label="Choose browser"
></vwc-textfield>
<vwc-menu id="menu">
<vwc-list-item>Edge</vwc-list-item>
<vwc-list-item>Firefox</vwc-list-item>
@yinonov
yinonov / input.scss
Created March 30, 2022 10:33
Generated by SassMeister.com.
@use 'sass:selector';
@use 'sass:list';
@use 'sass:map';
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
$all-appearances: (
filled: 'filled',
outlined: 'outlined',