get-ready-browser

1.0.2 • Public • Published

get-ready

=====

NPM version build status Test coverage David deps npm download

Fork from supershabam/ready

NodeJS mixin to add one-time ready event

Usage

Using ready or ready.mixin to add ready method to the given object.

const ready = require('get-ready');
const obj = {};
ready.mixin(obj);
 
// register a callback
obj.ready(() => console.log('ready'));
 
// mark ready
obj.ready(true);

Register

Register a callback to the callback stack, it will be called when mark as ready, see example above.

If the callback is undefined, register will return a promise.

obj.ready().then(() => console.log('ready'));
obj.ready(true);

If it has been ready, the callback will be called immediately.

// already ready
obj.ready(true);
obj.ready().then(() => console.log('ready'));

Warning: the callback is called after nextTick

Emit

Mark it as ready, you can simply using .ready(true).

You can also mark it not ready.

obj.ready(true);
// call immediately
obj.ready(() => console.log('ready'));
 
obj.ready(false);
obj.ready(() => throw 'don\'t run');

When exception throws, you can pass an error object, then the callback will receive it as the first argument.

obj.ready(err => console.log(err));
obj.ready(new Error('err'));

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    1
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i get-ready-browser

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • shaoshuai0102