Poller

Uses the Timer to poll for changes on an object. For example, this is useful for detecting when an element's size changes, since there's no DOM event for that.

Note: Although the poller fires on requestAnimationFrame, be wary for performance issues. Make sure to check if there's an alternative to polling.

import { Poller } from 'oblik/utils/poller'

let el = document.querySelector('.my-element')
let poller = new Poller(el, 'offsetWidth', 'offsetHeight')

poller.on('change', changes => {
    console.log(changes.offsetWidth?.newValue)
    console.log(changes.offsetHeight?.newValue)
})
← Math Query →