promise-polyfill
Advanced tools
Comparing version 1.0.1 to 1.0.5
{ | ||
"name": "promise-polyfill", | ||
"version": "1.0.1", | ||
"version": "1.0.5", | ||
"description": "Light weight promise polyfill. A+ compliant", | ||
@@ -5,0 +5,0 @@ "main": "Promise.js", |
(function(global) { | ||
if(global.Promise) return; | ||
if(typeof module !== 'undefined' && module.exports) { | ||
module.exports = Promise; | ||
} else { | ||
global.Promise = Promise; | ||
} | ||
var asap = (global && global.setImmediate) || function(fn){ setTimeout(fn, 0) }; | ||
@@ -8,2 +16,5 @@ function bind(fn, thisArg) { | ||
} | ||
function isArray(value) { | ||
return Array.isArray ? Array.isArray(value) : Object.prototype.toString.call(value) === "[object Array]" | ||
} | ||
function Promise(fn) { | ||
@@ -116,3 +127,3 @@ if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new') | ||
Promise.all = function () { | ||
var args = Array.prototype.slice.call(arguments.length === 1 && Array.isArray(arguments[0]) ? arguments[0] : arguments); | ||
var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments); | ||
@@ -165,7 +176,3 @@ return new Promise(function (resolve, reject) { | ||
if(typeof module !== 'undefined' && module.exports) { | ||
module.exports = Promise; | ||
} else { | ||
global.Promise = Promise; | ||
} | ||
})(this); |
@@ -1,5 +0,5 @@ | ||
(function(h){function f(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!==typeof this)throw new TypeError("Promises must be constructed via new");if("function"!==typeof a)throw new TypeError("not a function");this._value=this._state=null;this._deferreds=[];m(a,f(n,this),f(l,this))}function p(a){var b=this;null===this._state?this._deferreds.push(a):r(function(){var e=b._state?a.onFulfilled:a.onRejected;if(null===e)(b._state?a.resolve:a.reject)(b._value);else{var d;try{d=e(b._value)}catch(c){a.reject(c); | ||
return}a.resolve(d)}})}function n(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"===typeof a||"function"===typeof a)){var b=a.then;if("function"===typeof b){m(f(b,a),f(n,this),f(l,this));return}}this._state=!0;this._value=a;q.call(this)}catch(e){l.call(this,e)}}function l(a){this._state=!1;this._value=a;q.call(this)}function q(){for(var a=0,b=this._deferreds.length;a<b;a++)p.call(this,this._deferreds[a]);this._deferreds=null}function s(a,b,e,d){this.onFulfilled= | ||
"function"===typeof a?a:null;this.onRejected="function"===typeof b?b:null;this.resolve=e;this.reject=d}function m(a,b,e){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,e(a))})}catch(c){d||(d=!0,e(c))}}var r=h&&h.setImmediate||function(a){setTimeout(a,0)};c.prototype["catch"]=function(a){return this.then(null,a)};c.prototype.then=function(a,b){var e=this;return new c(function(d,c){p.call(e,new s(a,b,d,c))})};c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&Array.isArray(arguments[0])? | ||
arguments[0]:arguments);return new c(function(b,c){function d(g,k){try{if(k&&("object"===typeof k||"function"===typeof k)){var h=k.then;if("function"===typeof h){h.call(k,function(a){d(g,a)},c);return}}a[g]=k;0===--f&&b(a)}catch(l){c(l)}}if(0===a.length)return b([]);for(var f=a.length,g=0;g<a.length;g++)d(g,a[g])})};c.resolve=function(a){return new c(function(b){b(a)})};c.reject=function(a){return new c(function(b,c){c(a)})};c.race=function(a){return new c(function(b,c){a.map(function(a){a.then(b, | ||
c)})})};"undefined"!==typeof module&&module.exports?module.exports=c:h.Promise=c})(this); | ||
(function(e){function g(a,b){return function(){a.apply(b,arguments)}}function q(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}function c(a){if("object"!==typeof this)throw new TypeError("Promises must be constructed via new");if("function"!==typeof a)throw new TypeError("not a function");this._value=this._state=null;this._deferreds=[];l(a,g(m,this),g(h,this))}function n(a){var b=this;null===this._state?this._deferreds.push(a):r(function(){var f=b._state? | ||
a.onFulfilled:a.onRejected;if(null===f)(b._state?a.resolve:a.reject)(b._value);else{var d;try{d=f(b._value)}catch(c){a.reject(c);return}a.resolve(d)}})}function m(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"===typeof a||"function"===typeof a)){var b=a.then;if("function"===typeof b){l(g(b,a),g(m,this),g(h,this));return}}this._state=!0;this._value=a;p.call(this)}catch(f){h.call(this,f)}}function h(a){this._state=!1;this._value=a;p.call(this)}function p(){for(var a= | ||
0,b=this._deferreds.length;a<b;a++)n.call(this,this._deferreds[a]);this._deferreds=null}function s(a,b,f,d){this.onFulfilled="function"===typeof a?a:null;this.onRejected="function"===typeof b?b:null;this.resolve=f;this.reject=d}function l(a,b,f){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,f(a))})}catch(c){d||(d=!0,f(c))}}if(!e.Promise){"undefined"!==typeof module&&module.exports?module.exports=c:e.Promise=c;var r=e&&e.setImmediate||function(a){setTimeout(a,0)};c.prototype["catch"]= | ||
function(a){return this.then(null,a)};c.prototype.then=function(a,b){var f=this;return new c(function(d,c){n.call(f,new s(a,b,d,c))})};c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&q(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(e,k){try{if(k&&("object"===typeof k||"function"===typeof k)){var h=k.then;if("function"===typeof h){h.call(k,function(a){d(e,a)},c);return}}a[e]=k;0===--g&&b(a)}catch(l){c(l)}}if(0===a.length)return b([]);for(var g=a.length, | ||
e=0;e<a.length;e++)d(e,a[e])})};c.resolve=function(a){return new c(function(b){b(a)})};c.reject=function(a){return new c(function(b,c){c(a)})};c.race=function(a){return new c(function(b,c){a.map(function(a){a.then(b,c)})})}}})(this); |
@@ -18,9 +18,21 @@ Promise | ||
### Simple use | ||
### Node | ||
``` | ||
npm install promise-polyfill | ||
``` | ||
## Simple use | ||
``` | ||
var prom = new Promise(function(resolve, reject) { | ||
setTimeout(resolve, 1000); | ||
// do a thing, possibly async, then… | ||
if (/* everything turned out fine */) { | ||
resolve("Stuff worked!"); | ||
} | ||
else { | ||
reject(new Error("It broke")); | ||
} | ||
}); | ||
// Do something after 1000 milliseconds | ||
// Do something when async done | ||
prom.then(function() { | ||
@@ -27,0 +39,0 @@ ... |
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
9933
177
50