UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

38 lines (37 loc) 1.27 kB
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details. v3.2.1 */ import { isServer } from "lit"; function createObserver(type, callback, options) { if (isServer) { return void 0; } const Observer = getObserver(type); return new Observer(callback, options); } function getObserver(type) { class ExtendedMutationObserver extends window.MutationObserver { constructor(callback) { super(callback); this.observedEntry = []; this.callback = callback; } observe(target, options) { this.observedEntry.push({ target, options }); return super.observe(target, options); } unobserve(target) { const newObservedEntries = this.observedEntry.filter((observed) => observed.target !== target); this.observedEntry = []; this.callback(super.takeRecords(), this); this.disconnect(); newObservedEntries.forEach((observed) => this.observe(observed.target, observed.options)); } } return function() { return type === "intersection" ? window.IntersectionObserver : type === "mutation" ? ExtendedMutationObserver : window.ResizeObserver; }(); } export { createObserver as c };