Skip to content

elnarddogg/wee-promise

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 6 commits behind bernardmcmanus:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Promises/A+ logo

WeePromise

An ultra light (<1k minified / gzipped) Promises / A+ implementation.

travis-ci david-dm

Installation

npm i wee-promise --save

Usage

WeePromise supports both deferred and resolver patterns:

function asDeferred() {
	const deferred = new WeePromise();
	doSomethingAsync(deferred.resolve);
	return deferred;
}

function asResolver() {
	return new WeePromise((resolve) => {
		doSomethingAsync(resolve);
	});
}

as well as ES6-style all and race methods:

const arr = getCollectionOfPromises();

WeePromise.all(arr).then((result) => {
	// result is an array of all of the promise values in arr.
});

WeePromise.race(arr).then((result) => {
	// result is the value of the first resolved promise in arr.
});

and can be extended to create objects that behave as A+ compliant promises:

class Gnarly extends WeePromise {
	// ...
}

If you want to change WeePromise's async provider, just override WeePromise.async:

WeePromise.async = (cb) => {
	const img = new Image();
	img.onload = img.onerror = cb;
	img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
};

Build & Test

npm i && npm run build

About

An ultra light Promises / A+ implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.7%
  • HTML 2.3%