import { Injectable } from '@angular/core' ; import { Store , select , Action , } from '@ngrx/store' ; import { Observable } from 'rxjs' ; import { DaffProduct } from '@daffodil/product' ; import { DaffProductStateRootSlice } from '../../reducers/product-reducers-state.interface' ; import { getDaffProductSelectors } from '../../selectors/public_api' ; import { DaffProductFacadeInterface } from './product-facade.interface' ; inheritdoc @ Injectable ( { providedIn : 'root' , } ) export class DaffProductFacade < T extends DaffProduct = DaffProduct > implements DaffProductFacadeInterface < T > { loading$ : Observable < boolean > ; private selectors = getDaffProductSelectors < T > ( ) ; constructor ( private store ) { this . loading$ = this . store . pipe ( select ( this . selectors . selectCurrentProductLoadingState ) ) ; } getProduct ( id ) { return this . store . pipe ( select ( this . selectors . selectProduct ( id ) ) ) ; } getPrice ( id ) { return this . store . pipe ( select ( this . selectors . selectProductPrice ( id ) ) ) ; } hasDiscount ( id ) { return this . store . pipe ( select ( this . selectors . selectProductHasDiscount ( id ) ) ) ; } getDiscountAmount ( id ) { return this . store . pipe ( select ( this . selectors . selectProductDiscountAmount ( id ) ) ) ; } getDiscountedPrice ( id ) { return this . store . pipe ( select ( this . selectors . selectProductDiscountedPrice ( id ) ) ) ; } getDiscountPercent ( id ) { return this . store . pipe ( select ( this . selectors . selectProductDiscountPercent ( id ) ) ) ; } isOutOfStock ( id ) { return this . store . pipe ( select ( this . selectors . selectIsProductOutOfStock ( id ) ) ) ; } dispatch ( action ) { this . store . dispatch ( action ) ; } }