/** * External dependencies */ import { omit } from 'lodash'; import type { AnyAction } from '@nab/types'; /** * Internal dependencies */ import { INIT_STATE as IS } from '../config'; import type { State as FullState } from '../types'; type State = FullState[ 'experiment' ][ 'extensions' ]; import type { ExtensionAction } from '../actions/extensions'; import type { SetupEditor } from '../actions/editor'; type Action = ExtensionAction | SetupEditor; const INIT_STATE = IS.experiment.extensions; export function extensions( state = INIT_STATE, action: AnyAction ): State { return actualReducer( state, action as Action ) ?? state; } function actualReducer( state: State, action: Action ): State { switch ( action.type ) { case 'SET_EXTENSION': return { ...state, [ action.name ]: action.value, }; case 'REMOVE_EXTENSION': return omit( state, action.name ); case 'SETUP_EDITOR': return action.experiment.extensions ?? {}; } }