🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

prfun

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prfun - npm Package Compare versions

Comparing version
2.0.0
to
2.1.0
+3
-0
.travis.yml

@@ -8,1 +8,4 @@ language: node_js

- "0.8"
before_install:
- NODE_VERSION=$(node -e 'console.log(process.version.replace(/[.][0-9]+$/, ""))')
- if [ "v0.8" = "$NODE_VERSION" ]; then npm install -g npm@2.7.3 ; fi

@@ -0,1 +1,7 @@

# prfun 2.1.0 (2015-04-27)
* Switch from `es6-shim` to `core-js` by default.
* Fix our subclass code to follow the latest ES6 specification.
* Work around some bugs in native Promise implementations to allow
`prfun` to use native promises.
# prfun 2.0.0 (2015-04-23)

@@ -2,0 +8,0 @@ * Breaking change: `prfun` now creates a subclass of `Promise` by

@@ -7,12 +7,14 @@ // Utility functions for ES6 Promises.

if (!ParentPromise) { ParentPromise = global.Promise; }
// Try to use Promise implementation from es6-shim if there isn't already one
// Try to use Promise implementation from core-js if there isn't already one
// installed.
if (!ParentPromise) {
try {
require('es6-shim');
ParentPromise = require('core-js/library/es6/promise');
if (smash) {
global.Promise = ParentPromise;
}
} catch (e) {
throw new Error('No Promise implementation found. ' +
"Install the optional dependencies to use es6-shim's Promises.");
"Install the optional dependencies to use core-js's Promises.");
}
ParentPromise = global.Promise;
}

@@ -22,3 +24,6 @@

var PrFunPromise = function PrFunPromise(exec) {
return ParentPromise.call(this, exec);
var self = new ParentPromise(exec);
Object.setPrototypeOf(self, PrFunPromise.prototype);
self._promiseConstructor = PrFunPromise;
return self;
};

@@ -28,2 +33,18 @@ Object.setPrototypeOf(PrFunPromise, ParentPromise);

PrFunPromise.prototype.constructor = PrFunPromise;
// This isn't quite right: the way we are creating the subclass
// above doesn't set the internal [[PromiseConstructor]] field,
// so we need to tweak the implementation of Promise.resolve()
var makeResolve = function(parentResolve) {
return function(x) {
if (x && typeof x === 'object' && x._promiseConstructor) {
if (this === x._promiseConstructor) {
return x;
} else {
return new this(function(r) { r(x); });
}
}
return parentResolve.call(this, x);
};
};
PrFunPromise.resolve = makeResolve(PrFunPromise.resolve);

@@ -56,3 +77,7 @@ // Sometimes we just need to smash things (sigh)

var P = this || Promise;
return P.all(arguments);
// It shouldn't be necessary to slice the arguments, but some
// native Promise implementations don't recognize `arguments`
// as an iterable
var args = Array.prototype.slice.call(arguments);
return P.all(args);
};

@@ -346,3 +371,7 @@

var P = this || Promise;
return P.all(arguments).then(function(args) {
// It shouldn't be necessary to slice the arguments, but some
// native Promise implementations don't recognize `arguments`
// as an iterable
var args = Array.prototype.slice.call(arguments);
return P.all(args).then(function(args) {
var fn = args[0];

@@ -566,3 +595,6 @@ var ctx = args[1];

var BoundPromise = function BoundPromise(exec) {
return SuperPromise.call(this, exec);
var self = new SuperPromise(exec);
Object.setPrototypeOf(self, BoundPromise.prototype);
self._promiseConstructor = BoundPromise;
return self;
};

@@ -574,2 +606,3 @@ Object.setPrototypeOf(BoundPromise, SuperPromise);

// This re-definition of 'then' is where the actual work happens.
BoundPromise.prototype.then = (function(superThen) {

@@ -582,2 +615,6 @@ return function(f, r) {

})(BoundPromise.prototype.then);
// See discussion of PrFunPromise.resolve above:
BoundPromise.resolve = makeResolve(BoundPromise.resolve);
return newThis ? BoundPromise.resolve(this) : SuperPromise.resolve(this);

@@ -584,0 +621,0 @@ };

+6
-2

@@ -16,5 +16,9 @@ // Extra support for mocha.

var assert = require('assert');
// always use es6-shim promises for tests, since platform Promises may
// always use core-js promises for tests, since platform Promises may
// not properly implement ES6 subclasses
require('es6-shim');
delete global.Promise;
// Loading promises as a library was broken in core-js 0.9.0; it was fixed
// by zloirock/core-js@bba6d8d included in 0.9.1. Previously we needed to
// load all of core-js here to work around the issue.
// require('core-js');

@@ -21,0 +25,0 @@ // wrap specify/it and ensure that they always return a promise if synchronous.

{
"name": "prfun",
"version": "2.0.0",
"version": "2.1.0",
"description": "Helper functions for ES6 promises",
"main": "index.js",
"scripts": {
"test": "jshint . && jscs . && mocha --harmony-generators"
"mocha": "if which iojs ; then mocha ; else mocha --harmony-generators; fi",
"test": "jshint . && jscs . && npm run mocha"
},

@@ -26,3 +27,3 @@ "repository": {

"devDependencies": {
"es6-shim": ">=0.10.0 <1.0.0-0",
"core-js": "~0.9.1",
"jscs": "~1.12.0",

@@ -33,4 +34,4 @@ "jshint": "~2.7.0",

"optionalDependencies": {
"es6-shim": ">=0.10.0 <1.0.0-0"
"core-js": "~0.9.1"
}
}

@@ -12,5 +12,5 @@ # prfun

This package supplies them. It optionally loads [es6-shim] for the basic
`Promise` implementation, if there is not already a `Promise` implemention
present.
This package supplies them. It optionally loads a `Promise`
implementation from [core-js], if there is not already a `Promise`
implemention present.

@@ -26,3 +26,3 @@ Portions of the API and test suite are borrowed from [bluebird], [when],

var Promise = require('prfun'); // subclasses global.Promise
// note that global.Promise !== Promise here
// note that global.Promise !== Promise after this point
```

@@ -35,5 +35,5 @@ or

Note that the `SomeOtherPromise` implementation must support `Promise`
subclassing using ES6 semantics. ([es6-shim]'s implementation is
known to do so.) We will call the subclass created by `prfun` a
"`prfun` `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`".

@@ -1464,2 +1464,3 @@ According to the ES6 `Promise` spec, all `Promise` methods (including

[es6-shim]: https://github.com/paulmillr/es6-shim
[core-js]: https://github.com/zloirock/core-js

@@ -1466,0 +1467,0 @@ [NPM1]: https://nodei.co/npm/prfun.png