import { createSelectorWithArray } from '../utils/index' ; import { storeKey } from '../constant' ; import { Service } from '../interface' ; export const computed = ( depsCallback ) => ( target , key , descriptor ) => { if ( process . env . NODE_ENV === 'development' ) { if ( typeof descriptor . get !== 'function' ) { throw new Error ( `'@computed' should decorate a getter.` ) ; } if ( typeof depsCallback !== 'function' ) { throw new Error ( `@computed() parameter should be a selector function for dependencies collection.` ) ; } } const depsCallbackSelector = createSelectorWithArray ( ( that ) => [ that [ storeKey ] ?. getState ( ) ?? { } ] , function ( this ) { return depsCallback ( this ) ; } ) ; const selector = createSelectorWithArray ( ( that ) => depsCallbackSelector . call ( that ) , descriptor . get ! ) ; return { ... descriptor , get ( this ) { return selector . call ( this ) ; } } ; } ;