@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.94 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import"../has.js";import{equals as t}from"../lang.js";import"../Logger.js";import e from"../ObjectPool.js";import{Lifecycle as i}from"./interfaces.js";import{Property as s}from"./Property.js";import{OriginId as r,idToName as o,nameToId as a}from"./PropertyOrigin.js";import{Store as n}from"./Store.js";import{trackAccess as c,runTracked as l,initializeDependencyTracking as h}from"./tracking.js";import{Flags as p}from"./tracking/Flags.js";import{TrackingTarget as f}from"./tracking/TrackingTarget.js";function g(t,e,i){return void 0!==t}function m(t,e,s,r){return void 0!==t&&(!(null==s&&t.flags&p.NonNullable)||(r.lifecycle,i.INITIALIZING,!1))}class u{constructor(t){this.host=t,this.propertiesByName=new Map,this.ctorArgs=null,this.lifecycle=i.INITIALIZING,this.store=new n,this.mutable=!0,this._origin=r.USER;const e=this.host.constructor.__accessorMetadata__;for(const i in e){const t=new s(i,e[i]);this.propertiesByName.set(i,t)}this.metadata=e}initialize(){this.lifecycle=i.CONSTRUCTING}constructed(){this.lifecycle=i.CONSTRUCTED}destroy(){this.lifecycle=i.DESTROYED,this.propertiesByName.forEach((t=>t.destroy()))}get initialized(){return this.lifecycle!==i.INITIALIZING}get(t){const e=this.propertiesByName.get(t);if(e.metadata.get)return e.getComputed(this);this.mutable&&c(e);const i=this.store;return i.has(t)?i.get(t):e.metadata.value}originOf(t){const e=this.store.originOf(t);if(void 0===e){const e=this.propertiesByName.get(t);if(void 0!==e&&e.flags&p.HasDefaultValue)return"defaults"}return o(e)}has(t){return this.propertiesByName.has(t)&&this.store.has(t)}keys(){return[...this.propertiesByName.keys()]}internalGet(t){const e=this.propertiesByName.get(t);if(g(e))return this.store.has(t)?this.store.get(t):e.metadata.value}internalSet(t,e){const i=this.propertiesByName.get(t);g(i)&&this._internalSet(i,e)}getDependsInfo(t,e,i){const r=this.propertiesByName.get(e);if(!g(r))return"";const o=new f,a=l(o,(()=>r.metadata.get?.call(t)));let n=`${i}${t.declaredClass.split(".").pop()}.${e}: ${a}\n`;const c=o.accessed??new Set;if(0===c.size)return n;i+=" ";for(const l of c){if(!(l instanceof s))continue;n+=`${i}${l.propertyName}: undefined\n`}return n}setAtOrigin(t,e,i){const s=this.propertiesByName.get(t);if(g(s))return this._setAtOrigin(s,e,i)}isOverridden(t){const e=this.propertiesByName.get(t);return void 0!==e&&!!(e.flags&p.Overridden)}clearOverride(t){const e=this.propertiesByName.get(t);e&&e.flags&p.Overridden&&(e.flags&=~p.Overridden,e.notifyChange())}override(t,e){const i=this.propertiesByName.get(t);if(!m(i,t,e,this))return;const s=i.metadata.cast;if(s){const t=this._cast(s,e),{valid:i,value:r}=t;if(y.release(t),!i)return;e=r}i.flags|=p.Overridden,this._internalSet(i,e)}set(t,e){const i=this.propertiesByName.get(t);if(!m(i,t,e,this))return;const s=i.metadata.cast;if(s){const t=this._cast(s,e),{valid:i,value:r}=t;if(y.release(t),!i)return;e=r}const r=i.metadata.set;r?r.call(this.host,e):this._internalSet(i,e)}setDefaultOrigin(t){this._origin=a(t)}getDefaultOrigin(){return o(this._origin)}notifyChange(t){const e=this.propertiesByName.get(t);void 0!==e&&e.notifyChange()}invalidate(t){const e=this.propertiesByName.get(t);void 0!==e&&e.invalidate()}commit(t){const e=this.propertiesByName.get(t);void 0!==e&&e.commit()}_internalSet(t,e){const s=this.lifecycle!==i.INITIALIZING?this._origin:r.DEFAULTS;this._setAtOrigin(t,e,s)}_setAtOrigin(e,i,s){const r=this.store,o=e.propertyName;r.has(o,s)&&t(i,r.get(o))&&~e.flags&p.Overridden&&s===r.originOf(o)||(e.invalidate(),r.set(o,i,s),e.commit(),h(this.host,e))}_cast(t,e){const i=y.acquire();return i.valid=!0,i.value=e,t&&(i.value=t.call(this.host,e,i)),i}}class d{constructor(){this.value=null,this.valid=!0}acquire(){this.valid=!0}release(){this.value=null}}const y=new e(d);export{u as default};