import type * as d from '../declarations' ; import { BUILD } from '@app-data' ; import { consoleDevWarn , consoleError , getHostRef } from '@platform' ; import { HOST_FLAGS } from '@utils' ; import { parsePropertyValue } from './parse-property-value' ; import { scheduleUpdate } from './update-component' ; export const getValue = ( ref , propName ) => getHostRef ( ref ) . $instanceValues$ . get ( propName ) ; export const setValue = ( ref , propName , newVal , cmpMeta ) => { const hostRef = getHostRef ( ref ) ; const elm = BUILD . lazyLoad ? hostRef . $hostElement$ : ( ref as d . HostElement ) ; const oldVal = hostRef . $instanceValues$ . get ( propName ) ; const flags = hostRef . $flags$ ; const instance = BUILD . lazyLoad ? hostRef . $lazyInstance$ : ( elm as any ) ; newVal = parsePropertyValue ( newVal , cmpMeta . $members$ [ propName ] [ 0 ] ) ; if ( ( ! BUILD . lazyLoad || ! ( flags & HOST_FLAGS . isConstructingInstance ) || oldVal === undefined ) && newVal !== oldVal ) { hostRef . $instanceValues$ . set ( propName , newVal ) ; if ( BUILD . isDev ) { if ( hostRef . $flags$ & HOST_FLAGS . devOnRender ) { consoleDevWarn ( `The state/prop "${ propName }" changed during rendering. This can potentially lead to infinite-loops and other bugs.` , '\nElement' , elm , '\nNew value' , newVal , '\nOld value' , oldVal ) ; } else if ( hostRef . $flags$ & HOST_FLAGS . devOnDidLoad ) { consoleDevWarn ( `The state/prop "${ propName }" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"` , '\nElement' , elm , '\nNew value' , newVal , '\nOld value' , oldVal ) ; } } if ( ! BUILD . lazyLoad || instance ) { if ( BUILD . watchCallback && cmpMeta . $watchers$ && flags & HOST_FLAGS . isWatchReady ) { const watchMethods = cmpMeta . $watchers$ [ propName ] ; if ( watchMethods ) { watchMethods . map ( ( watchMethodName ) => { try { instance [ watchMethodName ] ( newVal , oldVal , propName ) ; } catch ( e ) { consoleError ( e , elm ) ; } } ) ; } } if ( BUILD . updatable && ( flags & ( HOST_FLAGS . hasRendered | HOST_FLAGS . isQueuedForUpdate ) ) === HOST_FLAGS . hasRendered ) { if ( BUILD . cmpShouldUpdate && instance . componentShouldUpdate ) { if ( instance . componentShouldUpdate ( newVal , oldVal , propName ) === false ) { return ; } } scheduleUpdate ( hostRef , false ) ; } } } } ;