import { StrategyIndex } from '../services/strategyIndex' ; import { StorageStrategies } from '../constants/strategy' ; import { StorageKeyManager } from './storageKeyManager' ; import { noop } from './noop' ; export class DecoratorBuilder { static buildSyncStrategyDecorator ( strategyName , prototype , propName , key ? , defaultValue = null ) { const rawKey = key || propName ; let storageKey ; Object . defineProperty ( prototype , propName , { get : function ( ) { let value ; StrategyIndex . get ( strategyName ) . get ( getKey ( ) ) . subscribe ( ( result ) => value = result ) ; return value === undefined ? defaultValue : value ; } , set : function ( value ) { StrategyIndex . get ( strategyName ) . set ( getKey ( ) , value ) . subscribe ( noop ) ; } } ) ; function getKey ( ) { if ( storageKey !== undefined ) return storageKey ; return storageKey = StorageKeyManager . normalize ( rawKey ) ; } } }