All Projects → lukechilds → When Dom Ready

lukechilds / When Dom Ready

Licence: mit
$(document).ready() for the 21st century

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to When Dom Ready

tall
Promise-based, No-dependency URL unshortner (expander) module for Node.js
Stars: ✭ 56 (-83.33%)
Mutual labels:  promise
Yaku
A lightweight promise library
Stars: ✭ 276 (-17.86%)
Mutual labels:  promise
Express Promise Router
A lightweight wrapper for Express 4's Router that allows middleware to return promises
Stars: ✭ 309 (-8.04%)
Mutual labels:  promise
rhea-promise
A promisified layer over rhea AMQP client
Stars: ✭ 23 (-93.15%)
Mutual labels:  promise
React Loads
React Loads is a backend agnostic library to help with external data fetching & caching in your UI components.
Stars: ✭ 268 (-20.24%)
Mutual labels:  promise
Rsup Progress
❤️ A simple progress bar with promises support
Stars: ✭ 290 (-13.69%)
Mutual labels:  promise
node-split-file
🌱 NodeJS Module to split and merge files for several purposes like transporting over unstable networks.
Stars: ✭ 33 (-90.18%)
Mutual labels:  promise
Vuejs Dialog
A lightweight, promise based alert, prompt and confirm dialog
Stars: ✭ 327 (-2.68%)
Mutual labels:  promise
Promise Timer
A trivial implementation of timeouts for Promises, built on top of ReactPHP.
Stars: ✭ 270 (-19.64%)
Mutual labels:  promise
Evt
💧EventEmitter's typesafe replacement
Stars: ✭ 305 (-9.23%)
Mutual labels:  promise
Vue Modal Dialogs
Promisify dialogs in Vue!
Stars: ✭ 259 (-22.92%)
Mutual labels:  promise
Osa Imessage
Send and receive iMessages with nodejs
Stars: ✭ 264 (-21.43%)
Mutual labels:  promise
Future
Streamlined Future<Value, Error> implementation
Stars: ✭ 291 (-13.39%)
Mutual labels:  promise
wxapp-api-interceptors
微信小程序api拦截器
Stars: ✭ 99 (-70.54%)
Mutual labels:  promise
Aigle
🦅 Aigle is an ideal promise library which is faster and more efficient than other libraries. It is a production-ready library that implements the Promise A+ standard.
Stars: ✭ 318 (-5.36%)
Mutual labels:  promise
asynqro
Futures and thread pool for C++ (with optional Qt support)
Stars: ✭ 103 (-69.35%)
Mutual labels:  promise
Mappersmith
is a lightweight rest client for node.js and the browser
Stars: ✭ 282 (-16.07%)
Mutual labels:  promise
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+1024.7%)
Mutual labels:  promise
Express Promise
❤️ Middleware for easy rendering of async Query results.
Stars: ✭ 320 (-4.76%)
Mutual labels:  promise
Promise
Ultra-performant Promise implementation in Python
Stars: ✭ 297 (-11.61%)
Mutual labels:  promise

when-dom-ready

$(document).ready() for the 21st century

Build Status Coverage Status npm

Returns a Promise for cleaner usage, provides a Promise chain helper function and can also be used as a pure function. The Promise will resolve instantly if the DOM is already ready.

Browser Compatibility

  • IE9+ (requires Promise polyfill)
  • Edge *
  • Firefox 29+
  • Safari 8+
  • Chrome 33+
  • Opera 23+

Install

npm install --save when-dom-ready

or for quick testing:

<script src="https://unpkg.com/when-dom-ready"></script>

Usage

import whenDomReady from 'when-dom-ready';

whenDomReady().then(() => console.log('DOM is ready yo!'));

You can still use callbacks if you want to:

whenDomReady(() => console.log('DOM is ready yo!'));

Promise chain helper

There is also a little helper function, whenDomReady.resume(), that pauses the execution of a Promise chain and then resumes it with the last value once the DOM is ready.

This allows you to specify complex async control flow in simple readable code:

fetch('/my-badass-api.json')
  .then(getSomeProcessingDoneWhileWaitingForDom)
  .then(whenDomReady.resume())
  .then(injectDataIntoDom);

Pure usage

You can make the function pure by passing in a document object. This is really useful for tests and mocking environments.

For example this works in Node.js:

const Window = require('window');
const whenDomReady = require('when-dom-ready');

const { document } = new Window();

whenDomReady(document).then(() => console.log('DOM is ready yo!'));

Again, you can use the callback version as a pure function too:

whenDomReady(() => console.log('DOM is ready yo!'), document);

And of course the helper:

//...
  .then(whenDomReady.resume(document))

License

MIT © Luke Childs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].