Skip to content
/ eprom Public

A deliberately incorrect resettable promise-like JavaScript async primitive powering untool's server-side rendering and module reloading. Mostly conforms with the Promises/A+ spec.

License

Notifications You must be signed in to change notification settings

untool/eprom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eprom

travis npm

eprom is an enhanced promise implementation. It works by wrapping a globally available Promise class and is as compliant with the Promises/A+ spec as the global Promise is.

In addition to the usual then, call and finally instance methods, it provides resolve and reject methods. In this regard, it resembles jQuery's Deferred object. On top of that, it features a reset method that enables repeat fulfillment.

Installation

Using NPM:

npm install -S eprom

Using Yarn:

yarn add eprom

API

eprom's EnhancedPromise mimics more usual Promises in every way. As such, it provides all class (resolve, reject, all, race) and instance (then, catch, finally) methods these provide.

enhancedPromise.resolve(value)

This method resolves an EnhancedPromise's inner Promise, triggering the execution of all onFulfilled handlers.

const enhancedPromise = new EnhancedPromise();
enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('foo');
// logs 'foo'

enhancedPromise.reject(reason)

This method rejects an EnhancedPromise's inner Promise, triggering the execution of all onRejected handlers.

const enhancedPromise = new EnhancedPromise();
enhancedPromise.catch(reason => console.err(reason));
enhancedPromise.reject('bar');
// logs 'bar'

enhancedPromise.reset()

This method creates a fresh inner Promise and thus allows for the re-fulfillment of an EnhancedPromise. A typical use case for this is handling repeat builds triggered by Webpack in watch mode.

const enhancedPromise = new EnhancedPromise();

enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('foo');
// logs 'foo'

enhancedPromise.reset();

enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('bar');
// logs 'bar'

About

A deliberately incorrect resettable promise-like JavaScript async primitive powering untool's server-side rendering and module reloading. Mostly conforms with the Promises/A+ spec.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published