import { DaffProduct } from '@daffodil/product' ; import { DaffProductPageActions , DaffProductPageActionTypes , } from '../../actions/public_api' ; import { DaffProductReducerState } from './product-reducer-state.interface' ; /**
 * Initial values of the product state.
 */ export const initialState = { currentProductId : null , qty : 1 , loading : false , errors : [ ] , } ; param state param action returns export function daffProductReducer < T extends DaffProduct > ( state = initialState , action ) { switch ( action . type ) { case DaffProductPageActionTypes . ProductPageLoadAction : case DaffProductPageActionTypes . ProductPageLoadByUrlAction : return { ... state , loading : true , currentProductId : null } ; case DaffProductPageActionTypes . ProductPageLoadSuccessAction : return { ... state , loading : false , currentProductId : action . payload . id } ; case DaffProductPageActionTypes . ProductPageLoadFailureAction : return { ... state , loading : false , errors : state . errors . concat ( new Array ( action . payload ) ) } ; case DaffProductPageActionTypes . UpdateQtyAction : return { ... state , qty : action . payload } ; default : return state ; } }