import { Action } from 'redux-actions' ; import { createDefinition } from '../../state/createDefinition' ; import { isObject , pick } from 'lodash' ; import { logWarning , makeError } from '../../utils' ; interface IState { [ key ] : any ; } export default createDefinition ( { reducers : { clear : ( ) : IState => ( { } ) , set : ( state , { payload = { } } ) : IState => payload , update : ( state , { payload = { } } ) : IState => { return { ... state , ... payload } ; } , } , transformInitialState : ( state , { namespacing } ) => { if ( ! isObject ( state ) ) { throw makeError ( `Definition Record at ${ namespacing . join ( '.' ) } initialState invalid` ) ; } return state ; } , defaultState : { } , selectors : { get : ( state , keys = undefined ) : { } => { if ( keys ) { if ( isObject ( state ) ) { return pick ( state , keys ) ; } logWarning ( 'Record state invalid, `get` returning undefined.' ) ; return { } ; } return state ; } , keys : ( state ) => Object . keys ( state ) , } , } ) ;