Skip to content

Run a JavaScript function as a separate browser event

Notifications You must be signed in to change notification settings

hliyan/js-defer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Run a JavaScript function as a separate browser event

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages