/** * External dependencies */ import { isEqual } from 'lodash'; import type { AnyAction } from '@nab/types'; /** * Internal dependencies */ import { INIT_STATE } from '../config'; import type { State as FullState } from '../types'; import type { SiteAction as Action } from '../actions/site-quota'; type State = FullState[ 'siteQuota' ]; export function siteQuota( state = INIT_STATE.siteQuota, action: AnyAction ): State { return actualReducer( state, action as Action ) ?? state; } function actualReducer( state: State, action: Action ): State { switch ( action.type ) { case 'RECEIVE_SITE_QUOTA': return isEqual( state, action.quota ) ? state : action.quota; } }