Schedule function on any DOM event during a browser's idle period. Perform background and low priority work on the main event loop, without impacting latency-critical events.
Installation
NPM
npm install inspecta
Yarn
yarn add inspecta
How to use
const inspecta = require('inspecta');
const button = document.getElementById('button');
/**
* Event listener will be added on `button` element which will execute callback on click.
*
* Callback will be executed during a browser's idle period.
*/
inspecta.on(button, 'click', e => {
console.log(`Event: ${e}`);
console.log('Callback was executed');
});
// Removes event listener from specified element.
inspecta.remove('click', button);
// Same as `on` function above, but instead of `button` element it will add event listener on `document` element.
inspecta.every('click', e => {
console.log(`Event: ${e}`);
console.log('Callback was executed');
});
// If there's no specified element it will be removed from `document` element.
inspecta.remove('click');