Comparing version 2.6.0 to 2.7.0
@@ -0,1 +1,10 @@ | ||
### 2.7.0 | ||
* Added [`promise.catch`](docs/api.md#catch) and [`promise.finally`](docs/api.md#finally) as synonyms for `promise.otherwise` and `promise.ensure`. (#212) | ||
* New [browserify build](../README.md#legacy-environments-via-browserify) for those using globals. (#209) | ||
* Added [ender](http://ender.jit.su) support to `package.json`. (#223) | ||
* Fix compatibility with [PhantomJS](http://phantomjs.org)'s CommonJS module support. (#226) | ||
* Fix [Sauce Labs](https://saucelabs.com) tests for pull requests. (#216) | ||
* Added `bower.json` `ignore` to trim files installed via bower. (#193) | ||
### 2.6.0 | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "when", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "A lightweight Promises/A+ and when() implementation, plus other async goodies.", | ||
"keywords": ["Promises/A+", "promises-aplus", "promise", "promises", "deferred", "deferreds", "when", "async", "asynchronous", "cujo"], | ||
"keywords": ["Promises/A+", "promises-aplus", "promise", "promises", "deferred", "deferreds", "when", "async", "asynchronous", "cujo", "ender"], | ||
"homepage": "http://cujojs.com", | ||
@@ -46,5 +46,7 @@ "licenses": [ | ||
"benchmark": "~1", | ||
"microtime": "~0" | ||
"microtime": "~0", | ||
"browserify": "~2" | ||
}, | ||
"main": "when", | ||
"ender": { "files": ["*.js", "node/*.js", "unfold/*.js", "monitor/*.js"] }, | ||
"directories": { | ||
@@ -58,4 +60,6 @@ "test": "test" | ||
"start": "buster static -e browser", | ||
"benchmark": "node benchmark/promise && node benchmark/map" | ||
"benchmark": "node benchmark/promise && node benchmark/map", | ||
"browserify": "browserify -s when build/when.browserify.js -o build/when.js", | ||
"browserify-debug": "browserify -s when build/when.browserify-debug.js -o build/when.js" | ||
} | ||
} | ||
} |
@@ -16,50 +16,11 @@ <a href="http://promises-aplus.github.com/promises-spec"><img src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png" alt="Promises/A+ logo" align="right" /></a> | ||
# What's New? | ||
- [What's new](CHANGES.md) | ||
- [API docs](docs/api.md#api) | ||
- [Examples](https://github.com/cujojs/when/wiki/Examples) | ||
- [More info on the wiki](https://github.com/cujojs/when/wiki) | ||
### 2.6.0 | ||
* New [`promise.done`](docs/api.md#done) allows consuming the ultimate value at the end of a promise chain while ensuring that any errors are thrown to the host environment so you get loud stack traces. | ||
* `when/node/function` [`bindCallback`](docs/api.md#nodefn-bindcallback) and [`liftCallback`](docs/api.md#nodefn-liftcallback) now behave more like standard node-style APIs in that they allow exceptions to propagate to the host environment for loud stack traces. | ||
### 2.5.1 | ||
* `ensure` now ignores non-functions, [like `then` does](http://promisesaplus.com/#point-25), for consistency. (#207) | ||
### 2.5.0 | ||
* [Promises/A+ 1.1](http://promisesaplus.com) compliant. Passes version 2.0.0 of the [Promises/A+ test suite](https://github.com/promises-aplus/promises-tests). | ||
### 2.4.1 | ||
* New `MutationObserver` scheduler further reduces "time-to-first-handler" in modern browsers. (#198) | ||
* Also, this works around a horrible IE10 bug (desktop and mobile) that renders `setImmediate`, `MessageChannel`, and `postMessage` unusable as fast task schedulers. Many thanks to @plaa and @calvinmetcalf for their help in discovering the problem and working out a solution. (#197) | ||
### 2.4.0 | ||
* Experimental support for [vert.x 2.x](http://vertx.io). Should now run in vert.x >= 1.1.0. | ||
* New `when.isPromiseLike` as the more accurately-named synonym for `when.isPromise`. | ||
* **DEPRECATED**: `when.isPromise`. It can only tell you that something is "promise-like" (aka "thenable") anyway. Use the new, more accurately-named `when.isPromiseLike` instead. | ||
* Fix for promise monitor reporting extra unhandled rejections for `when.all` and `when.map`. | ||
### 2.3.0 | ||
* New [`promise.tap`](docs/api.md#tap) for adding side effects to a promise chain. | ||
* New `MessageChannel` scheduler reduces "time-to-first" handler, in environments that support it. | ||
* Performance optimizations for promise resolution. | ||
* Internal architecture improvements to pave the way for when.js 3.0.0. | ||
[Full Changelog](CHANGES.md) | ||
# Docs & Examples | ||
[API docs](docs/api.md#api) | ||
[More info on the wiki](https://github.com/cujojs/when/wiki) | ||
[Examples](https://github.com/cujojs/when/wiki/Examples) | ||
Quick Start | ||
=========== | ||
----------- | ||
### AMD | ||
#### AMD | ||
@@ -80,3 +41,3 @@ 1. Get it | ||
### Node | ||
#### Node | ||
@@ -86,3 +47,3 @@ 1. `npm install when` | ||
### RingoJS | ||
#### RingoJS | ||
@@ -92,23 +53,21 @@ 1. `ringo-admin install cujojs/when` | ||
### Legacy environments | ||
#### Ender | ||
1. `git clone https://github.com/cujojs/when` or `git submodule add https://github.com/cujojs/when` | ||
1. Add a transient `define` shim, and a `<script>` element for when.js | ||
1. `ender add cujojs/when` | ||
2. `var when = require('when');` | ||
```html | ||
<script> | ||
window.define = function(factory) { | ||
try{ delete window.define; } catch(e){ window.define = void 0; } // IE | ||
window.when = factory(); | ||
}; | ||
window.define.amd = {}; | ||
</script> | ||
<script src="path/to/when/when.js"></script> | ||
``` | ||
#### Legacy environments (via browserify) | ||
1. `when` will be available as `window.when` | ||
1. `git clone https://github.com/cujojs/when` | ||
1. `npm install` | ||
1. `npm run browserify` to generate `build/when.js` | ||
1. Or `npm run browserify-debug` to build with [when/monitor/console](docs/api.md#debugging-promises) enabled | ||
1. `<script src="path/to/when/build/when.js"></script>` | ||
1. `when` will be available as `window.when` | ||
1. Other modules will be available as sub-objects/functions, e.g. `window.when.fn.lift`, `window.when.sequence`. See the [full sub-namespace list in the browserify build file](build/when.browserify.js) | ||
# Running the Unit Tests | ||
Running the Unit Tests | ||
---------------------- | ||
## Node | ||
#### Node | ||
@@ -118,10 +77,10 @@ Note that when.js includes the [Promises/A+ Test Suite](https://github.com/promises-aplus/promise-tests). Running unit tests in Node will run both when.js's own test suite, and the Promises/A+ Test Suite. | ||
1. `npm install` | ||
1. `npm test` | ||
2. `npm test` | ||
## Browsers | ||
#### Browsers | ||
1. `npm install` | ||
1. `npm start` - starts buster server & prints a url | ||
1. Point browsers at <buster server url>/capture, e.g. `localhost:1111/capture` | ||
1. `npm run-script test-browser` | ||
2. `npm start` - starts buster server & prints a url | ||
3. Point browsers at <buster server url>/capture, e.g. `localhost:1111/capture` | ||
4. `npm run-script test-browser` | ||
@@ -128,0 +87,0 @@ References |
225
when.js
@@ -12,5 +12,5 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */ | ||
* @author John Hann | ||
* @version 2.6.0 | ||
* @version 2.7.0 | ||
*/ | ||
(function(define, global) { 'use strict'; | ||
(function(define) { 'use strict'; | ||
define(function (require) { | ||
@@ -77,112 +77,112 @@ | ||
Promise.prototype = { | ||
/** | ||
* Register handlers for this promise. | ||
* @param [onFulfilled] {Function} fulfillment handler | ||
* @param [onRejected] {Function} rejection handler | ||
* @param [onProgress] {Function} progress handler | ||
* @return {Promise} new Promise | ||
*/ | ||
then: function(onFulfilled, onRejected, onProgress) { | ||
/*jshint unused:false*/ | ||
var args, sendMessage; | ||
var promisePrototype = Promise.prototype; | ||
args = arguments; | ||
sendMessage = this._message; | ||
/** | ||
* Register handlers for this promise. | ||
* @param [onFulfilled] {Function} fulfillment handler | ||
* @param [onRejected] {Function} rejection handler | ||
* @param [onProgress] {Function} progress handler | ||
* @return {Promise} new Promise | ||
*/ | ||
promisePrototype.then = function(onFulfilled, onRejected, onProgress) { | ||
/*jshint unused:false*/ | ||
var args, sendMessage; | ||
return _promise(function(resolve, reject, notify) { | ||
sendMessage('when', args, resolve, notify); | ||
}, this._status && this._status.observed()); | ||
}, | ||
args = arguments; | ||
sendMessage = this._message; | ||
/** | ||
* Register a rejection handler. Shortcut for .then(undefined, onRejected) | ||
* @param {function?} onRejected | ||
* @return {Promise} | ||
*/ | ||
otherwise: function(onRejected) { | ||
return this.then(undef, onRejected); | ||
}, | ||
return _promise(function(resolve, reject, notify) { | ||
sendMessage('when', args, resolve, notify); | ||
}, this._status && this._status.observed()); | ||
}; | ||
/** | ||
* Ensures that onFulfilledOrRejected will be called regardless of whether | ||
* this promise is fulfilled or rejected. onFulfilledOrRejected WILL NOT | ||
* receive the promises' value or reason. Any returned value will be disregarded. | ||
* onFulfilledOrRejected may throw or return a rejected promise to signal | ||
* an additional error. | ||
* @param {function} onFulfilledOrRejected handler to be called regardless of | ||
* fulfillment or rejection | ||
* @returns {Promise} | ||
*/ | ||
ensure: function(onFulfilledOrRejected) { | ||
return typeof onFulfilledOrRejected === 'function' | ||
? this.then(injectHandler, injectHandler)['yield'](this) | ||
: this; | ||
/** | ||
* Register a rejection handler. Shortcut for .then(undefined, onRejected) | ||
* @param {function?} onRejected | ||
* @return {Promise} | ||
*/ | ||
promisePrototype['catch'] = promisePrototype.otherwise = function(onRejected) { | ||
return this.then(undef, onRejected); | ||
}; | ||
function injectHandler() { | ||
return resolve(onFulfilledOrRejected()); | ||
} | ||
}, | ||
/** | ||
* Ensures that onFulfilledOrRejected will be called regardless of whether | ||
* this promise is fulfilled or rejected. onFulfilledOrRejected WILL NOT | ||
* receive the promises' value or reason. Any returned value will be disregarded. | ||
* onFulfilledOrRejected may throw or return a rejected promise to signal | ||
* an additional error. | ||
* @param {function} onFulfilledOrRejected handler to be called regardless of | ||
* fulfillment or rejection | ||
* @returns {Promise} | ||
*/ | ||
promisePrototype['finally'] = promisePrototype.ensure = function(onFulfilledOrRejected) { | ||
return typeof onFulfilledOrRejected === 'function' | ||
? this.then(injectHandler, injectHandler)['yield'](this) | ||
: this; | ||
/** | ||
* Terminate a promise chain by handling the ultimate fulfillment value or | ||
* rejection reason, and assuming responsibility for all errors. if an | ||
* error propagates out of handleResult or handleFatalError, it will be | ||
* rethrown to the host, resulting in a loud stack track on most platforms | ||
* and a crash on some. | ||
* @param {function?} handleResult | ||
* @param {function?} handleError | ||
* @returns {undefined} | ||
*/ | ||
done: function(handleResult, handleError) { | ||
this.then(handleResult, handleError).otherwise(crash); | ||
}, | ||
function injectHandler() { | ||
return resolve(onFulfilledOrRejected()); | ||
} | ||
}; | ||
/** | ||
* Shortcut for .then(function() { return value; }) | ||
* @param {*} value | ||
* @return {Promise} a promise that: | ||
* - is fulfilled if value is not a promise, or | ||
* - if value is a promise, will fulfill with its value, or reject | ||
* with its reason. | ||
*/ | ||
'yield': function(value) { | ||
return this.then(function() { | ||
return value; | ||
}); | ||
}, | ||
/** | ||
* Terminate a promise chain by handling the ultimate fulfillment value or | ||
* rejection reason, and assuming responsibility for all errors. if an | ||
* error propagates out of handleResult or handleFatalError, it will be | ||
* rethrown to the host, resulting in a loud stack track on most platforms | ||
* and a crash on some. | ||
* @param {function?} handleResult | ||
* @param {function?} handleError | ||
* @returns {undefined} | ||
*/ | ||
promisePrototype.done = function(handleResult, handleError) { | ||
this.then(handleResult, handleError).otherwise(crash); | ||
}; | ||
/** | ||
* Runs a side effect when this promise fulfills, without changing the | ||
* fulfillment value. | ||
* @param {function} onFulfilledSideEffect | ||
* @returns {Promise} | ||
*/ | ||
tap: function(onFulfilledSideEffect) { | ||
return this.then(onFulfilledSideEffect)['yield'](this); | ||
}, | ||
/** | ||
* Shortcut for .then(function() { return value; }) | ||
* @param {*} value | ||
* @return {Promise} a promise that: | ||
* - is fulfilled if value is not a promise, or | ||
* - if value is a promise, will fulfill with its value, or reject | ||
* with its reason. | ||
*/ | ||
promisePrototype['yield'] = function(value) { | ||
return this.then(function() { | ||
return value; | ||
}); | ||
}; | ||
/** | ||
* Assumes that this promise will fulfill with an array, and arranges | ||
* for the onFulfilled to be called with the array as its argument list | ||
* i.e. onFulfilled.apply(undefined, array). | ||
* @param {function} onFulfilled function to receive spread arguments | ||
* @return {Promise} | ||
*/ | ||
spread: function(onFulfilled) { | ||
return this.then(function(array) { | ||
// array may contain promises, so resolve its contents. | ||
return all(array, function(array) { | ||
return onFulfilled.apply(undef, array); | ||
}); | ||
/** | ||
* Runs a side effect when this promise fulfills, without changing the | ||
* fulfillment value. | ||
* @param {function} onFulfilledSideEffect | ||
* @returns {Promise} | ||
*/ | ||
promisePrototype.tap = function(onFulfilledSideEffect) { | ||
return this.then(onFulfilledSideEffect)['yield'](this); | ||
}; | ||
/** | ||
* Assumes that this promise will fulfill with an array, and arranges | ||
* for the onFulfilled to be called with the array as its argument list | ||
* i.e. onFulfilled.apply(undefined, array). | ||
* @param {function} onFulfilled function to receive spread arguments | ||
* @return {Promise} | ||
*/ | ||
promisePrototype.spread = function(onFulfilled) { | ||
return this.then(function(array) { | ||
// array may contain promises, so resolve its contents. | ||
return all(array, function(array) { | ||
return onFulfilled.apply(undef, array); | ||
}); | ||
}, | ||
}); | ||
}; | ||
/** | ||
* Shortcut for .then(onFulfilledOrRejected, onFulfilledOrRejected) | ||
* @deprecated | ||
*/ | ||
always: function(onFulfilledOrRejected, onProgress) { | ||
return this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress); | ||
} | ||
/** | ||
* Shortcut for .then(onFulfilledOrRejected, onFulfilledOrRejected) | ||
* @deprecated | ||
*/ | ||
promisePrototype.always = function(onFulfilledOrRejected, onProgress) { | ||
return this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress); | ||
}; | ||
@@ -807,4 +807,4 @@ | ||
var reduceArray, slice, fcall, nextTick, handlerQueue, | ||
setTimeout, funcProto, call, arrayProto, monitorApi, | ||
cjsRequire, MutationObserver, undef; | ||
funcProto, call, arrayProto, monitorApi, | ||
capturedSetTimeout, cjsRequire, MutationObs, undef; | ||
@@ -843,6 +843,2 @@ cjsRequire = require; | ||
// capture setTimeout to avoid being caught by fake timers | ||
// used in time based tests | ||
setTimeout = global.setTimeout; | ||
// Allow attaching the monitor to when() if env has no console | ||
@@ -854,6 +850,8 @@ monitorApi = typeof console !== 'undefined' ? console : when; | ||
// vertx and finally fall back to setTimeout | ||
/*global process*/ | ||
/*global process,document,setTimeout,MutationObserver,WebKitMutationObserver*/ | ||
if (typeof process === 'object' && process.nextTick) { | ||
nextTick = process.nextTick; | ||
} else if(MutationObserver = global.MutationObserver || global.WebKitMutationObserver) { | ||
} else if(MutationObs = | ||
(typeof MutationObserver === 'function' && MutationObserver) || | ||
(typeof WebKitMutationObserver === 'function' && WebKitMutationObserver)) { | ||
nextTick = (function(document, MutationObserver, drainQueue) { | ||
@@ -866,3 +864,3 @@ var el = document.createElement('div'); | ||
}; | ||
}(document, MutationObserver, drainQueue)); | ||
}(document, MutationObs, drainQueue)); | ||
} else { | ||
@@ -873,3 +871,6 @@ try { | ||
} catch(ignore) { | ||
nextTick = function(t) { setTimeout(t, 0); }; | ||
// capture setTimeout to avoid being caught by fake timers | ||
// used in time based tests | ||
capturedSetTimeout = setTimeout; | ||
nextTick = function(t) { capturedSetTimeout(t, 0); }; | ||
} | ||
@@ -959,2 +960,2 @@ } | ||
}); | ||
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }, this); | ||
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118961
6
34
2999
86