Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 613 Bytes

README.md

File metadata and controls

29 lines (20 loc) · 613 Bytes

js-defer

js-defer is a simple library that internally uses the postMessage API to run functions as a separate JavaScript event. This is based on David Baron's setTimeout with a shorter delay.

Usage:

const jsDefer = require('js-defer');
const {init, defer} = jsDefer;

init(window);

const button = document.getElementById('test');
button.addEventListener('click', () => {
  defer(() => {
    button.innerHTML = 'Deferred clicked';
  })
});

Running the test

cd test
parcel test.html

Then visit http://localhost:1234