@legumeinfo/web-components
Version:
Web Components for the Legume Information System and other AgBio databases
37 lines • 1.18 kB
JavaScript
/**
* A controller that wraps the {@link !ResizeObserver | `ResizeObserver`}, allowing
* components to subscribe to the events in a manner that triggers changes in the
* component's template when the event occurs.
*/
export class LisResizeObserverController {
/**
* @param host - The component that's using the controller.
* @param callback - A function to call in the host's scope when a resize event occurs.
*/
constructor(host, callback) {
(this.host = host).addController(this);
this._resizeObserver = new ResizeObserver(callback.bind(host));
}
/** @ignore */
hostDisconnected() {
// unobserve all observed elements
this._resizeObserver.disconnect();
}
/**
* Observes the given element.
*
* @param element - The element to be observed.
*/
observe(element) {
this._resizeObserver.observe(element);
}
/**
* Stops observing the given element.
*
* @param element - The element to stop observing.
*/
unobserve(element) {
this._resizeObserver.unobserve(element);
}
}
//# sourceMappingURL=lis-resize-observer-controller.js.map