File

feature-libs/cart/saved-cart/components/details/saved-cart-details.service.ts

Index

Properties
Methods

Constructor

constructor(routingService: RoutingService, savedCartService: SavedCartFacade)
Parameters :
Name Type Optional
routingService RoutingService No
savedCartService SavedCartFacade No

Methods

getCartDetails
getCartDetails()
getSavedCartId
getSavedCartId()
Returns : Observable<string>

Properties

Protected savedCart$
Default value : this.savedCartId$.pipe( filter((cartId) => Boolean(cartId)), tap((savedCartId: string) => this.savedCartService.loadSavedCart(savedCartId) ), switchMap((savedCartId: string) => this.savedCartService.get(savedCartId)), shareReplay({ bufferSize: 1, refCount: true }) )
Protected savedCartId$
Default value : this.routingService.getRouterState().pipe( map((routingData) => routingData.state.params.savedCartId), distinctUntilChanged() )
import { Injectable } from '@angular/core';
import { SavedCartFacade } from '@spartacus/cart/saved-cart/root';
import { Cart, RoutingService } from '@spartacus/core';
import { Observable } from 'rxjs';
import {
  distinctUntilChanged,
  filter,
  map,
  shareReplay,
  switchMap,
  tap,
} from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class SavedCartDetailsService {
  protected savedCartId$ = this.routingService.getRouterState().pipe(
    map((routingData) => routingData.state.params.savedCartId),
    distinctUntilChanged()
  );

  protected savedCart$ = this.savedCartId$.pipe(
    filter((cartId) => Boolean(cartId)),
    tap((savedCartId: string) =>
      this.savedCartService.loadSavedCart(savedCartId)
    ),
    switchMap((savedCartId: string) => this.savedCartService.get(savedCartId)),
    shareReplay({ bufferSize: 1, refCount: true })
  );

  constructor(
    protected routingService: RoutingService,
    protected savedCartService: SavedCartFacade
  ) {}

  getSavedCartId(): Observable<string> {
    return this.savedCartId$;
  }

  getCartDetails(): Observable<Cart | undefined> {
    return this.savedCart$;
  }
}

result-matching ""

    No results matching ""