CollectionFlattener.js 1.6 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as t}from"../chunks/tslib.es6.js";import o from"./Collection.js";import{HandleOwnerMixin as s}from"./HandleOwner.js";import{isSome as r,isNone as e}from"./maybe.js";import"./has.js";import"./Error.js";import"./Logger.js";import"./accessorSupport/watch.js";import{autorun as i}from"./accessorSupport/trackingUtils.js";import{property as n}from"./accessorSupport/decorators/property.js";import"./arrayUtils.js";import"./accessorSupport/ensureType.js";import{subclass as c}from"./accessorSupport/decorators/subclass.js";let l=class extends(s(o)){constructor(t){super(t),this.getCollections=null}initialize(){this.handles.add(i((()=>this._refresh())))}destroy(){this.getCollections=null}_refresh(){const t=r(this.getCollections)?this.getCollections():null;if(e(t))return void this.removeAll();let o=0;for(const s of t)r(s)&&(o=this._processCollection(o,s));this.splice(o,this.length)}_createNewInstance(t){return new o(t)}_processCollection(t,o){if(!o)return t;const s=this.itemFilterFunction?this.itemFilterFunction:t=>!!t;for(const r of o)if(r){if(s(r)){const o=this.indexOf(r,t);o>=0?o!==t&&this.reorder(r,t):this.add(r,t),++t}if(this.getChildrenFunction){const o=this.getChildrenFunction(r);if(Array.isArray(o))for(const s of o)t=this._processCollection(t,s);else t=this._processCollection(t,o)}}return t}};t([n()],l.prototype,"getCollections",void 0),t([n()],l.prototype,"getChildrenFunction",void 0),t([n()],l.prototype,"itemFilterFunction",void 0),l=t([c("esri.core.CollectionFlattener")],l);const p=l;export{p as default};