@discoveryjs/discovery
Version:
Frontend framework for rapid data (JSON) analysis, shareable serverless reports and dashboards
37 lines (36 loc) • 840 B
JavaScript
import { Observer } from "../observer.js";
const resizeObserverSupported = typeof ResizeObserver === "function";
export class ContentRect extends Observer {
static supported = resizeObserverSupported;
el;
observer;
constructor() {
super(null);
this.el = null;
this.observer = resizeObserverSupported ? new ResizeObserver((entries) => {
for (const entry of entries) {
this.set(entry.contentRect);
}
}) : null;
}
observe(el) {
if (this.observer === null) {
this.el = null;
return;
}
el = el || null;
if (this.el !== el) {
if (this.el !== null) {
this.observer.unobserve(this.el);
}
if (el !== null) {
this.observer.observe(el);
}
this.el = el;
}
}
dispose() {
this.el = null;
this.observer = null;
}
}