https://github.com/zordius/with-promise
An extended promise to keep the context persistently
https://github.com/zordius/with-promise
Last synced: about 1 year ago
JSON representation
An extended promise to keep the context persistently
- Host: GitHub
- URL: https://github.com/zordius/with-promise
- Owner: zordius
- License: other
- Created: 2014-12-25T10:01:58.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-03-29T07:40:33.000Z (over 9 years ago)
- Last Synced: 2024-10-06T03:20:19.029Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/with-promise
- Size: 405 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.txt
Awesome Lists containing this project
README
with-promise
===================
An extended promise to keep the context persistently
[](https://www.npmjs.org/package/with-promise) [](https://david-dm.org/zordius/with-promise) [](https://travis-ci.org/zordius/with-promise) [](https://codeclimate.com/github/zordius/with-promise) [](https://codeclimate.com/github/zordius/with-promise) [](LICENSE.txt)
[](https://saucelabs.com/u/zordius_oss)
Installation
------------
```sh
npm install with-promise
```
In browser:
```html
```
In an AMD loader:
```javascript
require('with-promise', function (WithPromise) {/*....*/});
```
In nodejs:
```javascript
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
-----
```javascript
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
});
```