import { EntityState } from '@ngrx/entity' ; import { DaffProduct } from '@daffodil/product' ; import { DaffProductGridActionTypes , DaffProductGridActions , DaffProductActionTypes , DaffProductActions , DaffBestSellersActionTypes , DaffBestSellersActions , DaffProductPageActions , DaffProductPageActionTypes , } from '../../actions/public_api' ; import { daffProductEntitiesAdapter } from './product-entities-reducer-adapter' ; param state param action returns export function daffProductEntitiesReducer < T extends DaffProduct > ( state = daffProductEntitiesAdapter < T > ( ) . getInitialState ( ) , action ) { const adapter = daffProductEntitiesAdapter < T > ( ) ; switch ( action . type ) { case DaffProductGridActionTypes . ProductGridLoadSuccessAction : return adapter . upsertMany ( action . payload , state ) ; case DaffBestSellersActionTypes . BestSellersLoadSuccessAction : return adapter . upsertMany ( action . payload , state ) ; case DaffProductPageActionTypes . ProductPageLoadSuccessAction : case DaffProductActionTypes . ProductLoadSuccessAction : return adapter . upsertMany ( action . payload . products , state ) ; case DaffProductGridActionTypes . ProductGridResetAction : return adapter . removeAll ( state ) ; default : return state ; } }