import { AsyncTranslateConfig } from "../interface/async-translate-config" ; import { translateConfigContainer } from '../core/translate-config-container' ; export function defineAsyncProperty ( model , propertyName , config ) { let observable = null ; let service = null ; let currentLanguage = null ; Object . defineProperty ( model . prototype , propertyName , { get : function ( ) { if ( ! observable || currentLanguage != translateConfigContainer . config . languageCode ) { if ( translateConfigContainer . injector ) { currentLanguage = translateConfigContainer . config . languageCode ; service = translateConfigContainer . injector . get ( config . serviceModel ) ; observable = config . serviceMethod . bind ( service ) . call ( ) ; } } else if ( currentLanguage != translateConfigContainer . config . languageCode ) observable = config . serviceMethod . bind ( service ) . call ( ) ; return observable ; } , enumerable : true , configurable : true } ) ; }