+2
-0
| language: node_js | ||
| node_js: | ||
| - "stable" | ||
| - "5.0" | ||
| - "4.4" | ||
| - "4.2" | ||
@@ -5,0 +7,0 @@ - "4.0" |
+5
-0
@@ -0,1 +1,6 @@ | ||
| # prfun 2.1.4 (2016-05-05) | ||
| * Add a cache to ensure that only a single `prfun` `Promise` class is | ||
| constructed even when using the wrapper interface. | ||
| * Update npm dev dependencies. | ||
| # prfun 2.1.3 (2015-12-11) | ||
@@ -2,0 +7,0 @@ * Optimize the `Promise` subclass constructor to avoid costly overhead |
+46
-1
| // Utility functions for ES6 Promises. | ||
| var FakeMap = function FakeMap() { | ||
| 'use strict'; | ||
| this.entries = []; | ||
| }; | ||
| FakeMap.prototype._getEntry = function _getEntry(key) { | ||
| 'use strict'; | ||
| var entries = this.entries; | ||
| for (var i = 0; i < entries.length; i++) { | ||
| if (entries[i].key === key) { return entries[i]; } | ||
| } | ||
| }; | ||
| FakeMap.prototype.set = function set(key, value) { | ||
| 'use strict'; | ||
| var entry = this._getEntry(key); | ||
| if (entry !== void 0) { | ||
| entry.value = value; | ||
| } else { | ||
| this.entries.push({ key: key, value: value }); | ||
| } | ||
| }; | ||
| FakeMap.prototype.get = function get(key) { | ||
| 'use strict'; | ||
| var entry = this._getEntry(key); | ||
| if (entry !== void 0) { | ||
| return entry.value; | ||
| } | ||
| }; | ||
| var makeMap = (function() { | ||
| 'use strict'; | ||
| var m = null; | ||
| return function() { | ||
| if (m === null) { | ||
| m = global.Map ? new global.Map() : new FakeMap(); | ||
| } | ||
| return m; | ||
| }; | ||
| })(); | ||
| module.exports = function(ParentPromise, smash) { | ||
@@ -20,2 +59,7 @@ 'use strict'; | ||
| } | ||
| // Use cached PrFun promise if possible. | ||
| var cache = makeMap(); | ||
| var PrFunPromise = smash ? null : cache.get(ParentPromise); | ||
| if (PrFunPromise) { return PrFunPromise; } | ||
| // Find an implementation of Object.setPrototypeOf | ||
@@ -34,3 +78,3 @@ var setPrototypeOf = Object.setPrototypeOf; | ||
| var makeResolve = null; | ||
| var PrFunPromise = (function makeSubclass(ParentPromise) { | ||
| PrFunPromise = (function makeSubclass(ParentPromise) { | ||
| var PrFunPromise; | ||
@@ -780,3 +824,4 @@ // jscs:disable maximumLineLength | ||
| if (!smash) { cache.set(ParentPromise, Promise); } | ||
| return Promise; | ||
| }; |
+6
-6
| { | ||
| "name": "prfun", | ||
| "version": "2.1.3", | ||
| "version": "2.1.4", | ||
| "description": "Helper functions for ES6 promises", | ||
@@ -31,10 +31,10 @@ "main": "index.js", | ||
| "devDependencies": { | ||
| "core-js": "~1.2.6", | ||
| "jscs": "~2.7.0", | ||
| "jshint": "~2.8.0", | ||
| "mocha": "~2.3.4" | ||
| "core-js": "^2.3.0", | ||
| "jscs": "^2.11.0", | ||
| "jshint": "^2.9.2", | ||
| "mocha": "^2.4.5" | ||
| }, | ||
| "optionalDependencies": { | ||
| "core-js": "~1.2.6" | ||
| "core-js": "^2.3.0" | ||
| } | ||
| } |
+8
-5
@@ -14,3 +14,3 @@ # prfun | ||
| implementation from [core-js], if there is not already a `Promise` | ||
| implemention present. The `prfun` package also requires an | ||
| implementation present. The `prfun` package also requires an | ||
| implementation of `Object.setPrototypeOf`; it will attempt to | ||
@@ -36,7 +36,9 @@ load this from [core-js] if not already present. Implementations | ||
| var Promise = require('prfun/wrap')( SomeOtherPromise ); | ||
| // Note that the same `Promise` object will always be | ||
| // returned if given the same `SomeOtherPromise` to wrap. | ||
| ``` | ||
| Note that the `SomeOtherPromise` implementation must support `Promise` | ||
| subclassing using ES6 semantics. (The implementations in [es6-shim] | ||
| and [core-js] are known to do so.) We will call the subclass created | ||
| by `prfun` a "`prfun` `Promise`". | ||
| subclassing using ES6 semantics. (The implementations in [babybird], | ||
| [es6-shim], and [core-js] are known to do so.) We will call the subclass | ||
| created by `prfun` a "`prfun` `Promise`". | ||
@@ -744,3 +746,3 @@ According to the ES6 `Promise` spec, all `Promise` methods (including | ||
| This is identical to `Promise#then` except that it does not return | ||
| a value. Some `Promise` implementations (for example, `babybird`) | ||
| a value. Some `Promise` implementations (for example, [babybird]) | ||
| export a `then0` implementation which is substantially faster than | ||
@@ -1487,2 +1489,3 @@ calling `Promise#then`. If such an implementation is present, its | ||
| [core-js]: https://github.com/zloirock/core-js | ||
| [babybird]: https://github.com/cscott/babybird | ||
@@ -1489,0 +1492,0 @@ [NPM1]: https://nodei.co/npm/prfun.png |
206855
0.71%4763
0.89%1497
0.2%