Loadable.js 2.0 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as o}from"../chunks/tslib.es6.js";import t from"./Error.js";import{EsriPromise as s}from"./Promise.js";import{onAbortOrThrow as r,onAbort as e}from"./promiseUtils.js";import l from"./Warning.js";import{property as a}from"./accessorSupport/decorators/property.js";import{subclass as n}from"./accessorSupport/decorators/subclass.js";const i="not-loaded",d="loading",c="failed",h="loaded",u=s=>{let u=class extends s{constructor(...o){super(...o),this._loadController=null,this.loadError=null,this.loadStatus="not-loaded",this._set("loadWarnings",[]),this.addResolvingPromise(new Promise((o=>{const s=this.load.bind(this);this.load=l=>{const a=new Promise(((o,s)=>{const e=r(l,s);this.destroyed&&s(new t("load:instance-destroyed",`Instance of '${this.declaredClass||this.constructor.name}' is already destroyed`,{instance:this})),this._promiseProps.when(o,s).finally((()=>{e&&e.remove()}))}));if(this.loadStatus===i){this._set("loadStatus",d);const o=this._loadController=new AbortController;s({signal:o.signal}),e(o.signal,(()=>{this._promiseProps.abort()}))}return o(),a}}))),this.when((()=>{this._set("loadStatus",h),this._loadController=null}),(o=>{this._set("loadStatus",c),this._set("loadError",o),this._loadController=null}))}get loaded(){return this.loadStatus===h}get loadWarnings(){return this._get("loadWarnings")}load(){return null}cancelLoad(){return this.isFulfilled()||(this._set("loadError",new t("load:cancelled","Cancelled")),this._loadController?.abort()),this}};return o([a({readOnly:!0})],u.prototype,"loaded",null),o([a({readOnly:!0})],u.prototype,"loadError",void 0),o([a({clonable:!1})],u.prototype,"loadStatus",void 0),o([a({type:[l],readOnly:!0})],u.prototype,"loadWarnings",null),u=o([n("esri.core.Loadable")],u),u};let p=class extends(u(s)){};p=o([n("esri.core.Loadable")],p),function(o){function t(o){return!(!o||!o.load)}o.LoadableMixin=u,o.isLoadable=t}(p||(p={}));const m=p;export{m as default};