In my cart service, I want to reset the state tree for example when a user logs out. How can I achieve this? Stackblitz playground stackblitz
export interface StateTree {
store: CartItem[];
cart: CartItem[];
tot: Totals,
checkout: boolean;
};
My variables.
private stateTree$ = new BehaviorSubject<StateTree>(null);
private checkoutTrigger$ = new BehaviorSubject<boolean>(false);
private cartAdd$ = new Subject<CartItem>();
private cartRemove$ = new Subject<CartItem>();
My sate
state$: Observable<StateTree> = this.stateTree$.pipe(
switchMap(() => this.getItems().pipe(
combineLatest([this.cart$, this.total$, this.checkoutTrigger$]),
debounceTime(0),
)),
map(([store, cart, tot, checkout]: any) => ({ store, cart, tot, checkout })),
tap(state => {
if (state.checkout) {
console.log('checkout', state);
}
}),
// make sure we share to the world! or just the entire app
shareReplay(1)
);