UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.54 kB
import t from"./Handles.js";import{destroyMaybe as r,isNone as e,isSome as s}from"./maybe.js";import{BEFORE_DESTROY_SYMBOL as o}from"./accessorSupport/beforeDestroy.js";import{get as i}from"./accessorSupport/get.js";import{getPropertiesMetadata as c}from"./accessorSupport/metadata.js";import a from"./accessorSupport/Properties.js";import{set as n}from"./accessorSupport/set.js";import{removeTarget as _,watch as h}from"./accessorSupport/watch.js";import{property as u}from"./accessorSupport/decorators/property.js";import{subclass as l}from"./accessorSupport/decorators/subclass.js";var p,d;function y(t){if(null==t)return{value:t};if(Array.isArray(t))return{type:[t[0]],value:null};switch(typeof t){case"object":return t.constructor?.__accessorMetadata__||t instanceof Date?{type:t.constructor,value:t}:t;case"boolean":return{type:Boolean,value:t};case"string":return{type:String,value:t};case"number":return{type:Number,value:t};case"function":return{type:t,value:null};default:return}}const f=Symbol("Accessor-Handles"),m=Symbol("Accessor-Initialized");class v{static createSubclass(t={}){if(Array.isArray(t))throw new Error("Multi-inheritance unsupported since 4.16");const{properties:r,declaredClass:e,constructor:s}=t;delete t.declaredClass,delete t.properties,delete t.constructor;const o=this;class i extends o{constructor(...t){super(...t),this.inherited=null,s&&s.apply(this,t)}}c(i.prototype);for(const c in t){const r=t[c];i.prototype[c]="function"==typeof r?function(...t){const e=this.inherited;let s;this.inherited=function(...t){if(o.prototype[c])return o.prototype[c].apply(this,t)};try{s=r.apply(this,t)}catch(i){throw this.inherited=e,i}return this.inherited=e,s}:t[c]}for(const c in r){const t=y(r[c]);u(t)(i.prototype,c)}return l(e)(i)}constructor(...t){if(this[p]=null,this[d]=!1,this.constructor===v)throw new Error("[accessor] cannot instantiate Accessor. This can be fixed by creating a subclass of Accessor");Object.defineProperty(this,"__accessor__",{enumerable:!1,value:new a(this)}),t.length>0&&this.normalizeCtorArgs&&(this.__accessor__.ctorArgs=this.normalizeCtorArgs.apply(this,t))}postscript(t){const r=this.__accessor__,e=r.ctorArgs||t;r.initialize(),e&&(this.set(e),r.ctorArgs=null),r.constructed(),this.initialize(),this[m]=!0}initialize(){}[o](){this[f]=r(this[f])}destroy(){this.destroyed||(_(this),this.__accessor__.destroy())}get constructed(){return this.__accessor__&&this.__accessor__.initialized||!1}get initialized(){return this[m]}get destroyed(){return this.__accessor__&&this.__accessor__.destroyed||!1}commitProperty(t){this.get(t)}get(t){return i(this,t)}hasOwnProperty(t){return this.__accessor__?this.__accessor__.has(t):Object.prototype.hasOwnProperty.call(this,t)}keys(){return this.__accessor__?this.__accessor__.keys():[]}set(t,r){return n(this,t,r),this}watch(t,r,e){return h(this,t,r,e)}own(t){this.addHandles(t)}addHandles(r,s){let o=this[f];e(o)&&(o=this[f]=new t),o.add(r,s)}removeHandles(t){const r=this[f];e(r)||r.remove(t)}hasHandles(t){const r=this[f];return!!s(r)&&r.has(t)}_override(t,r){void 0===r?this.__accessor__.clearOverride(t):this.__accessor__.override(t,r)}_clearOverride(t){return this.__accessor__.clearOverride(t)}_overrideIfSome(t,r){null==r?this.__accessor__.clearOverride(t):this.__accessor__.override(t,r)}_isOverridden(t){return this.__accessor__.isOverridden(t)}notifyChange(t){this.__accessor__.notifyChange(t)}_get(t){return this.__accessor__.internalGet(t)}_set(t,r){return this.__accessor__.internalSet(t,r),this}}p=f,d=m;export{v as default};