/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./PropertyOrigin","./tracking","./tracking/Flags","./tracking/ObservationHandle"],(function(t,s,e,i,n){"use strict";let l=function(){function t(t,s,e){this.properties=t,this.propertyName=s,this.metadata=e,this._observers=null,this._accessed=null,this._handles=null,this.flags=i.Flags.Dirty|(e.nonNullable?i.Flags.NonNullable:0)|(e.hasOwnProperty("value")?i.Flags.HasDefaultValue:0)|(void 0===e.get?i.Flags.DepTrackingInitialized:0)|(void 0===e.dependsOn?i.Flags.AutoTracked:0)}var l=t.prototype;return l.destroy=function(){if(this.flags&i.Flags.Dirty&&this._observers){const t=this._observers.slice();for(const s of t)s.onCommitted()}this._accessed=null,this._observers=null,this._clearObservationHandles()},l.getComputed=function(){e.trackAccess(this);const t=this.properties.store,n=this.propertyName,l=this.flags,r=t.get(n);if(l&i.Flags.Computing)return r;if(~l&i.Flags.Dirty&&t.has(n))return r;this.flags|=i.Flags.Computing;const a=this.properties.host;let o;l&i.Flags.AutoTracked?o=e.runTracked(this,this.metadata.get,a):(e.trackExplicitDependencies(a,this),o=this.metadata.get.call(a)),t.set(n,o,s.OriginId.COMPUTED);const h=t.get(n);return h===r?this.flags&=~i.Flags.Dirty:e.runUntracked(this.commit,this),this.flags&=~i.Flags.Computing,h},l.onObservableAccessed=function(t){t!==this&&(null===this._accessed&&(this._accessed=[]),this._accessed.includes(t)||this._accessed.push(t))},l.onTrackingEnd=function(){this._clearObservationHandles(),this.flags|=i.Flags.DepTrackingInitialized;const t=this._accessed;if(null===t)return;let s=this._handles;null===s&&(s=this._handles=[]);for(let e=0;e<t.length;++e)s.push(t[e].observe(this));t.length=0},l.observe=function(t){return null===this._observers&&(this._observers=[]),this._observers.includes(t)||this._observers.push(t),new n.ObservationHandle(this._observers,t)},l.notifyChange=function(){this.onInvalidated(),this.onCommitted()},l.invalidate=function(){this.onInvalidated()},l.onInvalidated=function(){~this.flags&i.Flags.Overriden&&(this.flags|=i.Flags.Dirty);const t=this._observers;if(null!==t)for(let s=0;s<t.length;++s)t[s].onInvalidated()},l.commit=function(){this.flags&=~i.Flags.Dirty,this.onCommitted()},l.onCommitted=function(){if(null===this._observers)return;const t=this._observers.slice();for(let s=0;s<t.length;++s)t[s].onCommitted()},l._clearObservationHandles=function(){const t=this._handles;if(null!==t){for(let s=0;s<t.length;++s)t[s].remove();t.length=0}},t}();t.Property=l,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
