UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.34 kB
import{_ as e}from"../../../../../chunks/tslib.es6.js";import t from"../../../../../core/Accessor.js";import{createAbortError as s,createResolver as r}from"../../../../../core/promiseUtils.js";import{property as o}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/accessorSupport/ensureType.js";import"../../../../../core/arrayUtils.js";import{subclass as i}from"../../../../../core/accessorSupport/decorators/subclass.js";let n=class extends t{constructor(e){super(e),this._queue=[],this._onGoingRequest=null,this._abortController=new AbortController}destroy(){this.clear()}get updating(){return!this.destroyed&&(this._queue.length>0||null!=this._onGoingRequest)}clear(){if(this.destroyed)throw new Error("instance is already destroyed");let e=this._queue.pop();for(;e;)e.resolver.reject(s()),e=this._queue.pop();this._queue.length=0,this._abortController.abort(),this._abortController=new AbortController}async push(e){if(this.destroyed)throw new Error("instance is already destroyed");const t=r();return this._queue.push({event:e,resolver:t}),this.notifyChange("updating"),Promise.resolve().then((()=>{this._processNext()})),t.promise}async _processNext(){if(this._onGoingRequest)return;const e=[],t=new Set,s=new Set,r=new Set;let o=this._queue.shift();for(;o;){const{event:{addedFeatures:i,deletedFeatures:n,updatedFeatures:u},resolver:l}=o;e.push(l);for(const{objectId:e,error:o}of i)o||null==e||(t.add(e),s.add(e),r.delete(e));for(const{objectId:e,error:t}of u)t||null==e||(s.add(e),r.delete(e));for(const{objectId:e,error:o}of n)o||null==e||(t.has(e)?t.delete(e):r.add(e),s.delete(e));o=this._queue.shift()}if(!s.size&&!r.size)return this.notifyChange("updating"),void e.forEach((e=>e()));const i=[],n=[];s.size&&s.forEach((e=>{i.push(e)})),r.size&&r.forEach((e=>{n.push(e)})),this._onGoingRequest=Promise.resolve().then((()=>this.processEdits(i,n,{signal:this._abortController.signal}))).catch((()=>{})),this.notifyChange("updating"),await this._onGoingRequest,this._onGoingRequest=null,this.notifyChange("updating"),e.forEach((e=>e())),this._queue.length>0&&this._processNext()}};e([o({constructOnly:!0})],n.prototype,"processEdits",void 0),e([o({readOnly:!0})],n.prototype,"updating",null),n=e([i("esri.views.2d.layers.features.controllers.EditsQueue")],n);export{n as EditsQueue};