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 40 41 42 43 44 45 | 7x 7x 7x 7x 7x 7x 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,
compareProducts,
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 }));
}
compareProducts(skus: string[]) {
this.store.dispatch(compareProducts({ skus }));
}
}
|