All files / src/app/extensions/tacton/store tacton-store.module.ts

87.5% Statements 21/24
50% Branches 2/4
50% Functions 1/2
86.95% Lines 20/23

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 533x 3x 3x 3x 3x   3x 3x 3x   3x 3x 3x 3x 3x 3x     3x           3x     3x                     3x                 3x   7x      
import { APP_BASE_HREF } from '@angular/common';
import { Inject, Injectable, InjectionToken, NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { ActionReducerMap, StoreConfig, StoreModule } from '@ngrx/store';
import { pick } from 'lodash-es';
 
import { DATA_RETENTION_POLICY } from 'ish-core/configurations/injection-keys';
import { InjectSingle } from 'ish-core/utils/injection';
import { dataRetentionMeta } from 'ish-core/utils/meta-reducers';
 
import { ProductConfigurationEffects } from './product-configuration/product-configuration.effects';
import { productConfigurationReducer } from './product-configuration/product-configuration.reducer';
import { SavedTactonConfigurationEffects } from './saved-tacton-configuration/saved-tacton-configuration.effects';
import { savedTactonConfigurationReducer } from './saved-tacton-configuration/saved-tacton-configuration.reducer';
import { TactonConfigEffects } from './tacton-config/tacton-config.effects';
import { tactonConfigReducer } from './tacton-config/tacton-config.reducer';
import { TactonState } from './tacton-store';
 
const tactonReducers: ActionReducerMap<TactonState> = {
  productConfiguration: productConfigurationReducer,
  tactonConfig: tactonConfigReducer,
  _savedTactonConfiguration: savedTactonConfigurationReducer,
};
 
const tactonEffects = [ProductConfigurationEffects, TactonConfigEffects, SavedTactonConfigurationEffects];
 
@Injectable()
export class DefaultTactonStoreConfig implements StoreConfig<TactonState> {
  metaReducers = [
    dataRetentionMeta<TactonState>(this.dataRetention.tacton, this.appBaseHref, 'tacton', '_savedTactonConfiguration'),
  ];
 
  constructor(
    @Inject(APP_BASE_HREF) private appBaseHref: string,
    @Inject(DATA_RETENTION_POLICY) private dataRetention: InjectSingle<typeof DATA_RETENTION_POLICY>
  ) {}
}
 
export const TACTON_STORE_CONFIG = new InjectionToken<StoreConfig<TactonState>>('tactonStoreConfig');
 
@NgModule({
  imports: [
    EffectsModule.forFeature(tactonEffects),
    StoreModule.forFeature('tacton', tactonReducers, TACTON_STORE_CONFIG),
  ],
  providers: [{ provide: TACTON_STORE_CONFIG, useClass: DefaultTactonStoreConfig }],
})
export class TactonStoreModule {
  static forTesting(...reducers: (keyof ActionReducerMap<TactonState>)[]) {
    return StoreModule.forFeature('tacton', pick(tactonReducers, reducers));
  }
}