/** * External dependencies */ import type { AnyAction } from '@nab/types'; /** * Internal dependencies */ import { INIT_STATE } from '../config'; import type { State as FullState } from '../types'; import type { ReusableEntityAction as Action } from '../actions/reusable-entities'; type State = FullState[ 'reusableEntities' ]; export function reusableEntities( state = INIT_STATE.reusableEntities, action: AnyAction ): State { return actualReducer( state, action as Action ) ?? state; } function actualReducer( state: State, action: Action ): State { switch ( action.type ) { case 'MARK_AS_SAVING_REUSABLE_ENTITIES': return { ...state, isSavingEntities: action.isSaving, }; case 'RECEIVE_REUSABLE_GOALS': return { ...state, goals: action.reusableGoals, }; case 'RECEIVE_REUSABLE_SEGMENTS': return { ...state, segments: action.reusableSegments, }; } }