@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 913 B
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{makeHandle as e}from"../handleUtils.js";import{ObservationHandle as r}from"./tracking/ObservationHandle.js";class s{constructor(){this._observers=null,this.destroyed=!1}observe(e){if(this.destroyed||e.destroyed)return t;null==this._observers&&(this._observers=[]);const s=this._observers;let o=!1,i=!1;for(const r of s)if(r.destroyed)i=!0;else if(r===e){o=!0;break}return o||(s.push(e),i&&this._removeDestroyedObservers()),new r(s,e)}_removeDestroyedObservers(){const e=this._observers;if(!e)return;const r=e.length;if(0===r)return;let s=0;for(let t=0;t<r;++t){for(;t+s<r;){if(!e[t+s].destroyed)break;++s}if(s>0){if(!(t+s<r))break;e[t]=e[t+s]}}e.length=r-s}destroy(){if(this.destroyed)return;this.destroyed=!0;const e=this._observers;if(null!=e){for(const r of e)r.onCommitted();this._observers=null}}}const t=e();export{s as ObservableBase};