All files / src/app/core/store/shopping shopping-store.module.ts

100% Statements 31/31
100% Branches 0/0
100% Functions 2/2
100% Lines 29/29

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 7317x 17x 17x 17x   17x 17x   17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x   17x 17x   17x                     17x                       17x 45x               17x                 17x   175x      
import { Injectable, InjectionToken, NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { ActionReducerMap, StoreConfig, StoreModule } from '@ngrx/store';
import { pick } from 'lodash-es';
 
import { personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { resetSubStatesOnActionsMeta } from 'ish-core/utils/meta-reducers';
 
import { CategoriesEffects } from './categories/categories.effects';
import { categoriesReducer } from './categories/categories.reducer';
import { FilterEffects } from './filter/filter.effects';
import { filterReducer } from './filter/filter.reducer';
import { ProductListingEffects } from './product-listing/product-listing.effects';
import { productListingReducer } from './product-listing/product-listing.reducer';
import { ProductPricesEffects } from './product-prices/product-prices.effects';
import { productPricesReducer } from './product-prices/product-prices.reducer';
import { ProductsEffects } from './products/products.effects';
import { productsReducer } from './products/products.reducer';
import { PromotionsEffects } from './promotions/promotions.effects';
import { promotionsReducer } from './promotions/promotions.reducer';
import { SearchEffects } from './search/search.effects';
import { searchReducer } from './search/search.reducer';
import { ShoppingState } from './shopping-store';
import { WarrantiesEffects } from './warranties/warranties.effects';
import { warrantiesReducer } from './warranties/warranties.reducer';
 
const shoppingReducers: ActionReducerMap<ShoppingState> = {
  categories: categoriesReducer,
  products: productsReducer,
  search: searchReducer,
  filter: filterReducer,
  promotions: promotionsReducer,
  productListing: productListingReducer,
  productPrices: productPricesReducer,
  warranties: warrantiesReducer,
};
 
const shoppingEffects = [
  CategoriesEffects,
  ProductsEffects,
  SearchEffects,
  FilterEffects,
  PromotionsEffects,
  ProductListingEffects,
  ProductPricesEffects,
  WarrantiesEffects,
];
 
@Injectable()
export class DefaultShoppingStoreConfig implements StoreConfig<ShoppingState> {
  metaReducers = [
    resetSubStatesOnActionsMeta<ShoppingState>(
      ['categories', 'products', 'search', 'filter', 'productPrices'],
      [personalizationStatusDetermined]
    ),
  ];
}
 
export const SHOPPING_STORE_CONFIG = new InjectionToken<StoreConfig<ShoppingState>>('shoppingStoreConfig');
 
@NgModule({
  imports: [
    EffectsModule.forFeature(shoppingEffects),
    StoreModule.forFeature('shopping', shoppingReducers, SHOPPING_STORE_CONFIG),
  ],
  providers: [{ provide: SHOPPING_STORE_CONFIG, useClass: DefaultShoppingStoreConfig }],
})
export class ShoppingStoreModule {
  static forTesting(...reducers: (keyof ActionReducerMap<ShoppingState>)[]) {
    return StoreModule.forFeature('shopping', pick(shoppingReducers, reducers));
  }
}