Comparing version 0.0.5 to 0.0.6
31
p.js
@@ -26,4 +26,7 @@ ;(function( factory ){ | ||
// window or worker | ||
wow = ot(typeof window) && window || ot(typeof worker) && worker; | ||
wow = ot(typeof window) && window || ot(typeof worker) && worker, | ||
toStr = head.toString, | ||
isArray; | ||
function onTick() { | ||
@@ -107,3 +110,7 @@ --pendingTicks; | ||
function each( arr, cb ) { | ||
isArray = Array.isArray || function( val ) { | ||
return !!val && toStr.call( val ) === "[object Array]"; | ||
}; | ||
function forEach( arr, cb ) { | ||
for ( var i = 0, l = arr.length; i < l; ++i ) { | ||
@@ -116,2 +123,13 @@ if ( i in arr ) { | ||
function each( obj, cb ) { | ||
if ( isArray(obj) ) { | ||
forEach( obj, cb ); | ||
return; | ||
} | ||
for ( var prop in obj ) { | ||
cb( obj[prop], prop ); | ||
} | ||
} | ||
function P( val ) { | ||
@@ -180,3 +198,3 @@ if ( val instanceof Promise ) { | ||
promise.value = value = val; | ||
each( pending, runLater ); | ||
forEach( pending, runLater ); | ||
pending = null; | ||
@@ -250,3 +268,3 @@ } | ||
P.allResolved = allResolved; | ||
function allResolved( promise ) { | ||
function allResolved( promises ) { | ||
var waiting = 1; | ||
@@ -259,5 +277,6 @@ var def = defer(); | ||
} | ||
each(promise, function( promise ) { | ||
each(promises, function( promise, index ) { | ||
++waiting; | ||
P( promise ).then( callback, callback ); | ||
promises[ index ] = promise = P( promise ); | ||
promise.then( callback, callback ); | ||
}); | ||
@@ -264,0 +283,0 @@ callback(); |
@@ -1,1 +0,1 @@ | ||
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define!=="function"){define(e)}else{P=e()}})(function(){"use strict";var e={f:null,w:false,n:null},n=e,t=true,o=0,i=0,f,r,u=s(typeof window)&&window||s(typeof worker)&&worker;function l(){--o;while(e.n){e=e.n;if(e.w){--i}var n=e.f;e.f=null;n()}t=true}function c(e,f){if(t&&++i>o){++o;r(l,0)}n=n.n={f:e,w:t,n:null};t=f===true}function s(e){return e==="object"||e==="function"}function a(e){return e==="function"}if(s(typeof process)&&process&&a(typeof process.nextTick)){r=process.nextTick}else if(u&&a(typeof u.setImmediate)){r=function(e){u.setImmediate(e)}}else if(a(typeof MessageChannel)){f=new MessageChannel;f.port1.onmessage=l;r=function(){f.port2.postMessage(0)}}else{r=setTimeout;if(u&&s(typeof Image)&&Image){(function(){var e=0;var n=function(e){var n=new Image;n.onerror=e;n.src="data:image/png,"};try{n(function(){if(--e===0){r=n}});++e}catch(t){}e&&setTimeout(function(){e=0},0)})()}}function p(e,n){for(var t=0,o=e.length;t<o;++t){if(t in e){n(e[t],t)}}}function v(e){if(e instanceof h){return e}var n=d();n.resolve(e);return n.promise}v.defer=d;function d(){var e=[],n=false,t=new h(i),o;function i(t,i){var f=d();function r(){var e=n?i:t;if(typeof e==="function"){try{f.resolve(e(o))}catch(r){f.reject(r)}}else if(n){f.reject(o)}else{f.fulfill(o)}}if(e){e.push(r)}else{c(r)}return f.promise}function f(n){if(e){if(n&&typeof n.then==="function"){n.then(r,u)}else{r(n)}}}function r(i){if(e){t.state=n?"rejected":"fulfilled";t.value=o=i;p(e,c);e=null}}function u(t){if(e){n=true;r(t)}}return{promise:t,resolve:f,fulfill:r,reject:u}}function h(e){this.then=e;this.state="pending";this.value=void 0}h.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,function(e){c(function(){if(v.onerror){v.onerror(e)}else{throw e}},true)})};h.prototype.spread=function(e,n){return this.then(e&&function(n){return e.apply(void 0,n)},n)};v.all=m;function m(e){var n=0;var t=d();p(e,function(o,i){++n;v(o).then(function(o){e[i]=o;if(--n===0){t.fulfill(e)}},t.reject)});if(n===0){t.fulfill(e)}return t.promise}v.allResolved=y;function y(e){var n=1;var t=d();function o(){if(--n===0){t.fulfill(e)}}p(e,function(e){++n;v(e).then(o,o)});o();return t.promise}v.onerror=null;v.prototype=h.prototype;v.nextTick=function(e){c(e,true)};return v}); | ||
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define!=="function"){define(e)}else{P=e()}})(function(){"use strict";var e={f:null,w:false,n:null},n=e,t=true,o=0,r=0,i,f,u=p(typeof window)&&window||p(typeof worker)&&worker,l=e.toString,c;function s(){--o;while(e.n){e=e.n;if(e.w){--r}var n=e.f;e.f=null;n()}t=true}function a(e,i){if(t&&++r>o){++o;f(s,0)}n=n.n={f:e,w:t,n:null};t=i===true}function p(e){return e==="object"||e==="function"}function v(e){return e==="function"}if(p(typeof process)&&process&&v(typeof process.nextTick)){f=process.nextTick}else if(u&&v(typeof u.setImmediate)){f=function(e){u.setImmediate(e)}}else if(v(typeof MessageChannel)){i=new MessageChannel;i.port1.onmessage=s;f=function(){i.port2.postMessage(0)}}else{f=setTimeout;if(u&&p(typeof Image)&&Image){(function(){var e=0;var n=function(e){var n=new Image;n.onerror=e;n.src="data:image/png,"};try{n(function(){if(--e===0){f=n}});++e}catch(t){}e&&setTimeout(function(){e=0},0)})()}}c=Array.isArray||function(e){return!!e&&l.call(e)==="[object Array]"};function d(e,n){for(var t=0,o=e.length;t<o;++t){if(t in e){n(e[t],t)}}}function h(e,n){if(c(e)){d(e,n);return}for(var t in e){n(e[t],t)}}function m(e){if(e instanceof w){return e}var n=y();n.resolve(e);return n.promise}m.defer=y;function y(){var e=[],n=false,t=new w(r),o;function r(t,r){var i=y();function f(){var e=n?r:t;if(typeof e==="function"){try{i.resolve(e(o))}catch(f){i.reject(f)}}else if(n){i.reject(o)}else{i.fulfill(o)}}if(e){e.push(f)}else{a(f)}return i.promise}function i(n){if(e){if(n&&typeof n.then==="function"){n.then(f,u)}else{f(n)}}}function f(r){if(e){t.state=n?"rejected":"fulfilled";t.value=o=r;d(e,a);e=null}}function u(t){if(e){n=true;f(t)}}return{promise:t,resolve:i,fulfill:f,reject:u}}function w(e){this.then=e;this.state="pending";this.value=void 0}w.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,function(e){a(function(){if(m.onerror){m.onerror(e)}else{throw e}},true)})};w.prototype.spread=function(e,n){return this.then(e&&function(n){return e.apply(void 0,n)},n)};m.all=g;function g(e){var n=0;var t=y();h(e,function(o,r){++n;m(o).then(function(o){e[r]=o;if(--n===0){t.fulfill(e)}},t.reject)});if(n===0){t.fulfill(e)}return t.promise}m.allResolved=j;function j(e){var n=1;var t=y();function o(){if(--n===0){t.fulfill(promise)}}h(e,function(t,r){++n;e[r]=t=m(t);t.then(o,o)});o();return t.promise}m.onerror=null;m.prototype=w.prototype;m.nextTick=function(e){a(e,true)};return m}); |
{ | ||
"name": "p-promise", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A simple Promises/A+ library.", | ||
@@ -5,0 +5,0 @@ "author": "Robert Katić <robert.katic@gmail.com> (https://github.com/rkatic)", |
10420
259