+4
-0
@@ -0,1 +1,5 @@ | ||
| # prfun 2.1.1 (2014-04-28) | ||
| * Improve compatibilty with environments missing a definition of | ||
| `Object.setPrototypeOf`. | ||
| # prfun 2.1.0 (2015-04-27) | ||
@@ -2,0 +6,0 @@ * Switch from `es6-shim` to `core-js` by default. |
+27
-16
@@ -20,2 +20,12 @@ // Utility functions for ES6 Promises. | ||
| } | ||
| // Find an implementation of Object.setPrototypeOf | ||
| var setPrototypeOf = Object.setPrototypeOf; | ||
| if (!setPrototypeOf) { | ||
| try { | ||
| setPrototypeOf = require('core-js/library/es6/object').setPrototypeOf; | ||
| } catch (e) { | ||
| throw new Error('No implementation of Object.setPrototypeOf found. ' + | ||
| "Install the optional dependencies to use core-js's implementation."); | ||
| } | ||
| } | ||
@@ -25,7 +35,7 @@ // Create a new Promise subclass (this is less cumbersome in es6!) | ||
| var self = new ParentPromise(exec); | ||
| Object.setPrototypeOf(self, PrFunPromise.prototype); | ||
| setPrototypeOf(self, PrFunPromise.prototype); | ||
| self._promiseConstructor = PrFunPromise; | ||
| return self; | ||
| }; | ||
| Object.setPrototypeOf(PrFunPromise, ParentPromise); | ||
| setPrototypeOf(PrFunPromise, ParentPromise); | ||
| PrFunPromise.prototype = Object.create(ParentPromise.prototype); | ||
@@ -166,3 +176,3 @@ PrFunPromise.prototype.constructor = PrFunPromise; | ||
| // helper for reduce/reduceAll | ||
| // Helper for reduce/reduceAll: | ||
| var reducer = function(P, callback) { | ||
@@ -305,3 +315,3 @@ return function(pPrev, pCurrent, index, arr) { | ||
| Promise.prototype['throw'] = function(e) { | ||
| // ensure that e is resolved, if it is a promise. | ||
| // Ensure that e is resolved, if it is a promise. | ||
| return this['return'](e).then(function(ee) { throw ee; }); | ||
@@ -312,10 +322,11 @@ }; | ||
| if (arguments.length > 0) { | ||
| // compatibility | ||
| // Compatibility with other libraries which allow arguments to #done() | ||
| return this.then.apply(this, arguments).done(); | ||
| } | ||
| this['catch'](function(e) { | ||
| // throw from new scope to ensure the exception will be unhandled | ||
| // Throw from new scope to ensure the exception will be unhandled | ||
| // (and thus reported). | ||
| setTimeout(function() { throw e; }, 0); | ||
| }); | ||
| // not chainable! | ||
| // This function is not chainable! Return `undefined`. | ||
| }; | ||
@@ -374,3 +385,3 @@ | ||
| // native Promise implementations don't recognize `arguments` | ||
| // as an iterable | ||
| // as an iterable. | ||
| var args = Array.prototype.slice.call(arguments); | ||
@@ -451,3 +462,3 @@ return P.all(args).then(function(args) { | ||
| if (typeof fn !== 'function') { | ||
| throw new TypeError('must wrap a function'); // fail fast | ||
| throw new TypeError('must wrap a function'); // Fail fast | ||
| } | ||
@@ -467,3 +478,3 @@ return function() { | ||
| var queueThrow = function(e) { | ||
| // don't let this exception get swallowed by the Promise handlers | ||
| // Don't let this exception get swallowed by the Promise handlers | ||
| setTimeout(function() { throw e; }, 0); | ||
@@ -596,10 +607,10 @@ }; | ||
| var SuperPromise = this._bindSuper || this.constructor || Promise; | ||
| // create a new Promise subclass (this is less cumbersome in es6, sigh) | ||
| // Create a new Promise subclass (this is less cumbersome in es6, sigh) | ||
| var BoundPromise = function BoundPromise(exec) { | ||
| var self = new SuperPromise(exec); | ||
| Object.setPrototypeOf(self, BoundPromise.prototype); | ||
| setPrototypeOf(self, BoundPromise.prototype); | ||
| self._promiseConstructor = BoundPromise; | ||
| return self; | ||
| }; | ||
| Object.setPrototypeOf(BoundPromise, SuperPromise); | ||
| setPrototypeOf(BoundPromise, SuperPromise); | ||
| BoundPromise.prototype = Object.create(SuperPromise.prototype); | ||
@@ -630,4 +641,4 @@ BoundPromise.prototype.constructor = BoundPromise; | ||
| var generator, callback, errback; | ||
| // when verb is "send", arg is a value | ||
| // when verb is "throw", arg is an exception | ||
| // When verb is "send", arg is a value | ||
| // When verb is "throw", arg is an exception | ||
| function continuer(verb, arg) { | ||
@@ -640,3 +651,3 @@ var result; | ||
| } | ||
| // xxx: possibly check for array-like (or iterable) value and | ||
| // XXX: Possibly check for array-like (or iterable) value and | ||
| // use Promise.all() before returning/invoking callback? | ||
@@ -643,0 +654,0 @@ if (result.done) { |
+3
-3
@@ -16,4 +16,4 @@ // Extra support for mocha. | ||
| var assert = require('assert'); | ||
| // always use core-js promises for tests, since platform Promises may | ||
| // not properly implement ES6 subclasses | ||
| // Always use core-js promises for tests, since platform Promises may | ||
| // not properly implement ES6 subclasses. | ||
| delete global.Promise; | ||
@@ -25,3 +25,3 @@ // Loading promises as a library was broken in core-js 0.9.0; it was fixed | ||
| // wrap specify/it and ensure that they always return a promise if synchronous. | ||
| // Wrap specify/it and ensure that they always return a promise if synchronous. | ||
| var onlypromises = function(f) { | ||
@@ -28,0 +28,0 @@ return function(title, cb) { |
+2
-2
| { | ||
| "name": "prfun", | ||
| "version": "2.1.0", | ||
| "version": "2.1.1", | ||
| "description": "Helper functions for ES6 promises", | ||
@@ -28,3 +28,3 @@ "main": "index.js", | ||
| "core-js": "~0.9.1", | ||
| "jscs": "~1.12.0", | ||
| "jscs": "~1.13.0", | ||
| "jshint": "~2.7.0", | ||
@@ -31,0 +31,0 @@ "mocha": "~2.2.4" |
+7
-3
@@ -14,3 +14,6 @@ # prfun | ||
| implementation from [core-js], if there is not already a `Promise` | ||
| implemention present. | ||
| implemention present. The `prfun` package also requires an | ||
| implementation of `Object.setPrototypeOf`; it will attempt to | ||
| load this from [core-js] if not already present. Implementations | ||
| loaded from [core-js] do not pollute the global namespace. | ||
@@ -22,4 +25,5 @@ Portions of the API and test suite are borrowed from [bluebird], [when], | ||
| By default `prfun` creates a `Promise` subclass, using ES6 semantics. | ||
| This means you use it like: | ||
| Unlike many other utility packages for `Promise`, `prfun` does not | ||
| pollute the global namespace. By default `prfun` creates a `Promise` | ||
| subclass, using ES6 semantics. This means you use it like: | ||
| ``` | ||
@@ -26,0 +30,0 @@ var Promise = require('prfun'); // subclasses global.Promise |
+1
-0
@@ -467,2 +467,3 @@ // jscs:disable maximumLineLength | ||
| }).caught(TypeError, function(e) { | ||
| // Uncomment to show the TypeError stack | ||
| // console.error(e.stack); | ||
@@ -469,0 +470,0 @@ caught = true; |
+2
-2
@@ -91,3 +91,3 @@ // jscs:disable maximumLineLength | ||
| assert.equal(typeof Promise.guard.n(1), 'function'); | ||
| // return a promise from all synchronous tests, for consistency | ||
| // Return a promise from all synchronous tests, for consistency | ||
| return Promise.resolve(); | ||
@@ -99,3 +99,3 @@ }); | ||
| assert.equal(typeof c().then, 'function'); | ||
| // return a promise from all synchronous tests, for consistency | ||
| // Return a promise from all synchronous tests, for consistency | ||
| return Promise.resolve(); | ||
@@ -102,0 +102,0 @@ }); |
@@ -41,3 +41,3 @@ 'use strict'; | ||
| assert(typeof (resolved([1, 2]).spread().then) === 'function'); | ||
| // return a promise from all synchronous tests, for consistency | ||
| // Return a promise from all synchronous tests, for consistency | ||
| return resolved(); | ||
@@ -44,0 +44,0 @@ }); |
198552
0.5%4591
0.26%1476
0.27%