All files / src/app/extensions/compare/facades compare.facade.ts

78.57% Statements 11/14
75% Branches 3/4
50% Functions 3/6
76.92% Lines 10/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 406x 6x 6x   6x   6x                     6x 3x   3x 3x     1x                              
import { Injectable } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable, switchMap } from 'rxjs';
 
import { toObservable } from 'ish-core/utils/functions';
 
import {
  addToCompare,
  getCompareProductsCount,
  getCompareProductsSKUs,
  isInCompareProducts,
  removeFromCompare,
  toggleCompare,
} from '../store/compare';
 
/* eslint-disable @typescript-eslint/member-ordering */
@Injectable({ providedIn: 'root' })
export class CompareFacade {
  constructor(private store: Store) {}
 
  compareProducts$ = this.store.pipe(select(getCompareProductsSKUs));
  compareProductsCount$ = this.store.pipe(select(getCompareProductsCount));
 
  inCompareProducts$(sku: string | Observable<string>) {
    return toObservable(sku).pipe(switchMap(plainSKU => this.store.pipe(select(isInCompareProducts(plainSKU)))));
  }
 
  addProductToCompare(sku: string) {
    this.store.dispatch(addToCompare({ sku }));
  }
 
  toggleProductCompare(sku: string) {
    this.store.dispatch(toggleCompare({ sku }));
  }
 
  removeProductFromCompare(sku: string) {
    this.store.dispatch(removeFromCompare({ sku }));
  }
}