Sha256: e2cdf3458e4b28f56c284003080727ccc85e5230c73c81aefc566718ab98f286
Contents?: true
Size: 802 Bytes
Versions: 16
Compression:
Stored size: 802 Bytes
Contents
export default function withSizeObserver(props = {}) { return function (component) { const resizeTarget = props.target || component.$root; const oldDestroy = component.destroy; const sizeObserver = Alpine.reactive({ observer: null, handler(target) { if (component.onResize) { component.onResize(target.contentRect, target); } }, }); sizeObserver.observer = new ResizeObserver((entries) => sizeObserver.handler(entries[0]) ); Object.assign(component, { destroy() { sizeObserver.observer.disconnect(); sizeObserver.observer = null; if (oldDestroy) { oldDestroy.call(this); } }, }); sizeObserver.observer.observe(resizeTarget); return component; }; }
Version data entries
16 entries across 16 versions & 1 rubygems