123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- import { forceUpdate } from '@stencil/core/internal/client/index.js';
- import { c as createObserver } from './observers.js';
- const observed = new Set();
- let mutationObserver;
- const observerOptions = { childList: true };
- /**
- * Helper to set up a conditional slot component on connectedCallback.
- *
- * @param component
- */
- function connectConditionalSlotComponent(component) {
- if (!mutationObserver) {
- mutationObserver = createObserver("mutation", processMutations);
- }
- mutationObserver.observe(component.el, observerOptions);
- }
- /**
- * Helper to tear down a conditional slot component on disconnectedCallback.
- *
- * @param component
- */
- function disconnectConditionalSlotComponent(component) {
- observed.delete(component.el);
- // we explicitly process queued mutations and disconnect and reconnect
- // the observer until MutationObserver gets an `unobserve` method
- // see https://github.com/whatwg/dom/issues/126
- processMutations(mutationObserver.takeRecords());
- mutationObserver.disconnect();
- for (const [element] of observed.entries()) {
- mutationObserver.observe(element, observerOptions);
- }
- }
- function processMutations(mutations) {
- mutations.forEach(({ target }) => {
- forceUpdate(target);
- });
- }
- export { connectConditionalSlotComponent as c, disconnectConditionalSlotComponent as d };
|