/** * External dependencies */ import type { AnyAction } from '@nab/types'; /** * Internal dependencies */ import { INIT_STATE } from '../config'; import type { State as FullState } from '../types'; import type { RecommendationEngineAction as Action } from '../actions/recommendation-engine'; type State = FullState[ 'recommendationEngine' ]; export function recommendationEngine( state = INIT_STATE.recommendationEngine, action: AnyAction ): State { return actualReducer( state, action as Action ) ?? state; } function actualReducer( state: State, action: Action ): State { switch ( action.type ) { case 'INIT_RECOMMENDATION_ENGINE_DATA': return { ...state, ...action.data, }; case 'MARK_OPPORTUNTIY_AS_BEING_INSTANTIATED': return { ...state, instantiatingOpportunity: action.opportunity, }; case 'SET_SUGGESTION_GENERATION_STATE': return { ...state, suggestionGenerationState: action.state, }; } }