with-promise

0.0.4 • Public • Published

with-promise

An extended promise to keep the context persistently

npm version Dependency Status Build Status Test Coverage Code Climate License

Sauce Test Status

Installation

npm install with-promise

In browser:

<script src="dist/with-promise.js"></script>

In an AMD loader:

require('with-promise', function (WithPromise) {/*....*/});

In nodejs:

var WithPromise =  require('with-promise');

Features

  • Extended Promise, make all .then() , .catch() handlers be executed with your assigned context: this .

Notice

You should use polyfills providing Promise to ensure with-promise works well. You can try polyfill.io or polyfills.io. For nodejs, you can try es6-promise or ypromise.

Usage

var WithPromise = require('with-promise');
 
// create a Promise by a resolver function and set context
var myPromise = WithPromise.create(resolver, context);
 
// create a resolved Promise
var myPromise = WithPromise.resolve(value, context);
 
// create a rejected Promise
var myPromise = WithPromise.reject(value, context);
 
// wrap Promise.all with context
var allPromises = WithPromise.all(promises, context);
 
 
// all this == context
myPromise.then(function () {
    // this == context
}).then(function () {
    // this == context
}).catch(function () {
    // this == context
});

Readme

Keywords

Package Sidebar

Install

npm i with-promise

Weekly Downloads

0

Version

0.0.4

License

none

Last publish

Collaborators

  • zordius