UNPKG

@grail-ui/svelte

Version:

[![NPM](https://img.shields.io/npm/v/@grail-ui/svelte)](https://www.npmjs.com/package/@grail-ui/svelte) [![minified](https://img.shields.io/bundlephobia/min/@grail-ui/svelte)](https://bundlephobia.com/package/@grail-ui/svelte) [![minified + zipped](https:

25 lines (24 loc) 1.05 kB
export function observeElement(element, property, callback, delay = 0) { const elementPrototype = Object.getPrototypeOf(element); // eslint-disable-next-line no-prototype-builtins if (elementPrototype.hasOwnProperty(property)) { const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, property); Object.defineProperty(element, property, { get: function () { // eslint-disable-next-line prefer-rest-params return descriptor?.get?.apply(this, arguments); }, set: function () { const oldValue = this[property]; // eslint-disable-next-line prefer-rest-params descriptor?.set?.apply(this, arguments); const newValue = this[property]; if (typeof callback == 'function') { setTimeout(callback.bind(this, oldValue, newValue), delay); } return newValue; }, configurable: true, }); } }