Comparing version 0.3.2 to 0.3.3
@@ -9,3 +9,3 @@ /** | ||
* | ||
* @version 0.3.2 | ||
* @version 0.3.3 | ||
*/ | ||
@@ -235,3 +235,3 @@ | ||
return arguments.length? | ||
this.isPromise(val)? | ||
Vow.isPromise(val)? | ||
val : | ||
@@ -243,23 +243,23 @@ new Promise(val) : | ||
when : function(obj, onFulfilled, onRejected, onProgress, ctx) { | ||
return this.promise(obj).then(onFulfilled, onRejected, onProgress, ctx); | ||
return Vow.promise(obj).then(onFulfilled, onRejected, onProgress, ctx); | ||
}, | ||
fail : function(obj, onRejected, ctx) { | ||
return this.when(obj, undef, onRejected, ctx); | ||
return Vow.when(obj, undef, onRejected, ctx); | ||
}, | ||
always : function(obj, onResolved, ctx) { | ||
return this.promise(obj).always(onResolved, ctx); | ||
return Vow.promise(obj).always(onResolved, ctx); | ||
}, | ||
progress : function(obj, onProgress, ctx) { | ||
return this.promise(obj).progress(onProgress, ctx); | ||
return Vow.promise(obj).progress(onProgress, ctx); | ||
}, | ||
spread : function(obj, onFulfilled, onRejected, ctx) { | ||
return this.promise(obj).spread(onFulfilled, onRejected, ctx); | ||
return Vow.promise(obj).spread(onFulfilled, onRejected, ctx); | ||
}, | ||
done : function(obj) { | ||
this.isPromise(obj) && obj.done(); | ||
Vow.isPromise(obj) && obj.done(); | ||
}, | ||
@@ -272,19 +272,19 @@ | ||
valueOf : function(obj) { | ||
return this.isPromise(obj)? obj.valueOf() : obj; | ||
return Vow.isPromise(obj)? obj.valueOf() : obj; | ||
}, | ||
isFulfilled : function(obj) { | ||
return this.isPromise(obj)? obj.isFulfilled() : true; | ||
return Vow.isPromise(obj)? obj.isFulfilled() : true; | ||
}, | ||
isRejected : function(obj) { | ||
return this.isPromise(obj)? obj.isRejected() : false; | ||
return Vow.isPromise(obj)? obj.isRejected() : false; | ||
}, | ||
isResolved : function(obj) { | ||
return this.isPromise(obj)? obj.isResolved() : true; | ||
return Vow.isPromise(obj)? obj.isResolved() : true; | ||
}, | ||
fulfill : function(val) { | ||
return this.when(val, undef, function(err) { | ||
return Vow.when(val, undef, function(err) { | ||
return err; | ||
@@ -295,3 +295,3 @@ }); | ||
reject : function(err) { | ||
return this.when(err, function(val) { | ||
return Vow.when(err, function(val) { | ||
var promise = new Promise(); | ||
@@ -304,3 +304,3 @@ promise.reject(val); | ||
resolve : function(val) { | ||
return this.isPromise(val)? val : this.when(val); | ||
return Vow.isPromise(val)? val : Vow.when(val); | ||
}, | ||
@@ -310,6 +310,6 @@ | ||
try { | ||
return this.promise(fn.apply(null, slice.call(arguments, 1))); | ||
return Vow.promise(fn.apply(null, slice.call(arguments, 1))); | ||
} | ||
catch(e) { | ||
return this.reject(e); | ||
return Vow.reject(e); | ||
} | ||
@@ -322,3 +322,3 @@ }, | ||
while(i < len) { | ||
this.when(promises[keys? keys[i] : i], onFulfilled, onRejected); | ||
Vow.when(promises[keys? keys[i] : i], onFulfilled, onRejected); | ||
++i; | ||
@@ -356,3 +356,3 @@ } | ||
this.forEach(promises, onFulfilled, onRejected, keys); | ||
Vow.forEach(promises, onFulfilled, onRejected, keys); | ||
@@ -380,3 +380,3 @@ return resPromise; | ||
this.forEach(promises, onProgress, onProgress, keys); | ||
Vow.forEach(promises, onProgress, onProgress, keys); | ||
@@ -404,3 +404,3 @@ return resPromise; | ||
this.forEach(promises, onFulfilled, onRejected); | ||
Vow.forEach(promises, onFulfilled, onRejected); | ||
@@ -411,7 +411,7 @@ return resPromise; | ||
delay : function(val, timeout) { | ||
return this.promise(val).delay(timeout); | ||
return Vow.promise(val).delay(timeout); | ||
}, | ||
timeout : function(val, timeout) { | ||
return this.promise(val).timeout(timeout); | ||
return Vow.promise(val).timeout(timeout); | ||
} | ||
@@ -422,11 +422,6 @@ }; | ||
nextTick = (function() { | ||
if(typeof process === 'object') { // nodejs | ||
return process.nextTick; | ||
} | ||
if(global.setImmediate) { // ie10 | ||
return global.setImmediate; | ||
} | ||
var fns = [], | ||
enqueueFn = function(fn) { | ||
return fns.push(fn) === 1; | ||
}, | ||
callFns = function() { | ||
@@ -440,2 +435,14 @@ var fnsToCall = fns, i = 0, len = fns.length; | ||
if(typeof process === 'object') { // nodejs | ||
return function(fn) { | ||
enqueueFn(fn) && process.nextTick(callFns); | ||
}; | ||
} | ||
if(global.setImmediate) { // ie10 | ||
return function(fn) { | ||
enqueueFn(fn) && global.setImmediate(callFns); | ||
}; | ||
} | ||
if(global.postMessage) { // modern browsers | ||
@@ -466,3 +473,3 @@ var isPostMessageAsync = true; | ||
return function(fn) { | ||
fns.push(fn) === 1 && global.postMessage(msg, '*'); | ||
enqueueFn(fn) && global.postMessage(msg, '*'); | ||
}; | ||
@@ -485,3 +492,3 @@ } | ||
return function(fn) { | ||
fns.push(fn) === 1 && createScript(); | ||
enqueueFn(fn) && createScript(); | ||
}; | ||
@@ -491,3 +498,3 @@ } | ||
return function(fn) { // old browsers | ||
setTimeout(fn, 0); | ||
enqueueFn(fn) && setTimeout(callFns, 0); | ||
}; | ||
@@ -494,0 +501,0 @@ })(), |
{ | ||
"name" : "vow", | ||
"version" : "0.3.2", | ||
"version" : "0.3.3", | ||
"description" : "Promises/A+ proposal compatible promises library", | ||
@@ -5,0 +5,0 @@ "homepage" : "https://github.com/dfilatov/jspromise", |
@@ -34,7 +34,7 @@ <a href="http://promises-aplus.github.com/promises-spec"><img src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png" align="right" /></a> | ||
* [valueOf](#valueof) | ||
* [then](#thenonfulfilled-onrejected-onprogress) | ||
* [fail](#failonrejected) | ||
* [always](#alwaysonresolved) | ||
* [progress](#progressonprogress) | ||
* [spread](#spreadonfulfilled-onrejected) | ||
* [then](#thenonfulfilled-onrejected-onprogress-context) | ||
* [fail](#failonrejected-context) | ||
* [always](#alwaysonresolved-context) | ||
* [progress](#progressonprogress-context) | ||
* [spread](#spreadonfulfilled-onrejected-context) | ||
* [done](#done) | ||
@@ -121,3 +121,3 @@ * [delay](#delaydelay) | ||
####then([onFulfilled], [onRejected], [onProgress])#### | ||
####then([onFulfilled], [onRejected], [onProgress], [context])#### | ||
Arranges for: | ||
@@ -127,2 +127,3 @@ * ````onFulfilled```` to be called with the value after promise is fulfilled, | ||
* ````onProgress```` to be called with the value when promise is notified for progress. | ||
* ````context```` context of callbacks | ||
@@ -135,7 +136,8 @@ Returns a new promise. See [Promises/A+ specification](https://github.com/promises-aplus/promises-spec) for details. | ||
function() { }, // to be called after promise is rejected | ||
function() { } // to be called when promise is notified); | ||
function() { } // to be called when promise is notified | ||
); | ||
```` | ||
####fail(onRejected)#### | ||
Arranges to call ````onRejected```` on the promise's rejection reason if it is rejected. Shortcut for ````then(null, onRejected)````. | ||
####fail(onRejected, [context])#### | ||
Arranges to call ````onRejected```` with given ````context```` on the promise's rejection reason if it is rejected. Shortcut for ````then(null, onRejected)````. | ||
````javascript | ||
@@ -149,4 +151,4 @@ var promise = Vow.promise(); | ||
####always(onResolved)#### | ||
Arranges to call ````onResolved```` on the promise if it is fulfilled or rejected. | ||
####always(onResolved, [context])#### | ||
Arranges to call ````onResolved```` with given ````context```` on the promise if it is fulfilled or rejected. | ||
````javascript | ||
@@ -160,6 +162,7 @@ var promise = Vow.promise(); | ||
####progress(onProgress)#### | ||
####progress(onProgress, [context])#### | ||
Arranges to call ````onProgress```` with given ````context```` on the promise if it is notified. | ||
Shortcut for ````then(null, null, onProgress)````. | ||
####spread([onFulfilled], [onRejected])#### | ||
####spread([onFulfilled], [onRejected], [context])#### | ||
Like "then", but "spreads" the array into a variadic value handler. | ||
@@ -166,0 +169,0 @@ It useful with [Vow.all](#allpromises), [Vow.allResolved](#allresolvedpromises) methods. |
@@ -116,3 +116,3 @@ module.exports = { | ||
process.nextTick(function() { | ||
resOrder.push(4); | ||
resOrder.push(6); | ||
process.nextTick(function() { | ||
@@ -127,7 +127,7 @@ resOrder.push(7); | ||
promise.then(function() { | ||
resOrder.push(5); | ||
resOrder.push(4); | ||
}); | ||
promise.then(function() { | ||
resOrder.push(6); | ||
resOrder.push(5); | ||
}); | ||
@@ -134,0 +134,0 @@ |
@@ -116,3 +116,3 @@ module.exports = { | ||
process.nextTick(function() { | ||
resOrder.push(4); | ||
resOrder.push(6); | ||
process.nextTick(function() { | ||
@@ -127,7 +127,7 @@ resOrder.push(7); | ||
promise.then(null, function() { | ||
resOrder.push(5); | ||
resOrder.push(4); | ||
}); | ||
promise.then(null, function() { | ||
resOrder.push(6); | ||
resOrder.push(5); | ||
}); | ||
@@ -134,0 +134,0 @@ |
@@ -9,3 +9,3 @@ /** | ||
* | ||
* @version 0.3.2 | ||
*/(function(e){var t=function(e){this._res=e,this._isFulfilled=!!arguments.length,this._isRejected=!1,this._fulfilledCallbacks=[],this._rejectedCallbacks=[],this._progressCallbacks=[]};t.prototype={valueOf:function(){return this._res},isFulfilled:function(){return this._isFulfilled},isRejected:function(){return this._isRejected},isResolved:function(){return this._isFulfilled||this._isRejected},fulfill:function(e){if(this.isResolved())return;this._isFulfilled=!0,this._res=e,this._callCallbacks(this._fulfilledCallbacks,e),this._fulfilledCallbacks=this._rejectedCallbacks=this._progressCallbacks=r},reject:function(e){if(this.isResolved())return;this._isRejected=!0,this._res=e,this._callCallbacks(this._rejectedCallbacks,e),this._fulfilledCallbacks=this._rejectedCallbacks=this._progressCallbacks=r},notify:function(e){if(this.isResolved())return;this._callCallbacks(this._progressCallbacks,e)},then:function(e,n,i,s){n&&!o(n)?(s=n,n=r):i&&!o(i)&&(s=i,i=r);var u=new t,a;return this._isRejected||(a={promise:u,fn:o(e)?e:r,ctx:s},this._isFulfilled?this._callCallbacks([a],this._res):this._fulfilledCallbacks.push(a)),this._isFulfilled||(a={promise:u,fn:n,ctx:s},this._isRejected?this._callCallbacks([a],this._res):this._rejectedCallbacks.push(a)),this.isResolved()||this._progressCallbacks.push({promise:u,fn:i,ctx:s}),u},fail:function(e,t){return this.then(r,e,t)},always:function(e,t){var n=this,r=function(){return e(n)};return this.then(r,r,t)},progress:function(e,t){return this.then(r,r,e,t)},spread:function(e,t,n){return this.then(function(t){return e.apply(this,t)},t,n)},done:function(){this.fail(s)},delay:function(e){return this.then(function(n){var r=new t;return setTimeout(function(){r.fulfill(n)},e),r})},timeout:function(e){var n=new t,r=setTimeout(function(){n.reject(Error("timed out"))},e);return n.sync(this),n.always(function(){clearTimeout(r)}),n},sync:function(e){var t=this;e.then(function(e){t.fulfill(e)},function(e){t.reject(e)})},_callCallbacks:function(e,t){var r=e.length;if(!r)return;var s=this.isResolved(),o=this.isFulfilled();i(function(){var i=0,u,a,f;while(i<r){u=e[i++],a=u.promise,f=u.fn;if(f){var l=u.ctx,c;try{c=l?f.call(l,t):f(t)}catch(h){a.reject(h);continue}s?n.isPromise(c)?function(e){c.then(function(t){e.fulfill(t)},function(t){e.reject(t)})}(a):a.fulfill(c):a.notify(c)}else s?o?a.fulfill(t):a.reject(t):a.notify(t)}})}};var n={promise:function(e){return arguments.length?this.isPromise(e)?e:new t(e):new t},when:function(e,t,n,r,i){return this.promise(e).then(t,n,r,i)},fail:function(e,t,n){return this.when(e,r,t,n)},always:function(e,t,n){return this.promise(e).always(t,n)},progress:function(e,t,n){return this.promise(e).progress(t,n)},spread:function(e,t,n,r){return this.promise(e).spread(t,n,r)},done:function(e){this.isPromise(e)&&e.done()},isPromise:function(e){return e&&o(e.then)},valueOf:function(e){return this.isPromise(e)?e.valueOf():e},isFulfilled:function(e){return this.isPromise(e)?e.isFulfilled():!0},isRejected:function(e){return this.isPromise(e)?e.isRejected():!1},isResolved:function(e){return this.isPromise(e)?e.isResolved():!0},fulfill:function(e){return this.when(e,r,function(e){return e})},reject:function(e){return this.when(e,function(e){var n=new t;return n.reject(e),n})},resolve:function(e){return this.isPromise(e)?e:this.when(e)},invoke:function(e){try{return this.promise(e.apply(null,u.call(arguments,1)))}catch(t){return this.reject(t)}},forEach:function(e,t,n,r){var i=r?r.length:e.length,s=0;while(s<i)this.when(e[r?r[s]:s],t,n),++s},all:function(e){var r=new t,i=f(e),s=i?l(e):c(e),o=s.length,u=i?[]:{};if(!o)return r.fulfill(u),r;var a=o,h=function(){if(!--a){var t=0;while(t<o)u[s[t]]=n.valueOf(e[s[t++]]);r.fulfill(u)}},p=function(e){r.reject(e)};return this.forEach(e,h,p,s),r},allResolved:function(e){var n=new t,r=f(e),i=r?l(e):c(e),s=i.length,o=r?[]:{};if(!s)return n.fulfill(o),n;var u=function(){--s||n.fulfill(e)};return this.forEach(e,u,u,i),n},any:function(e){var n=new t,r=e.length;if(!r)return n.reject(Error()),n;var i=0,s,o=function(e){n.fulfill(e)},u=function(e){i||(s=e),++i===r&&n.reject(s)};return this.forEach(e,o,u),n},delay:function(e,t){return this.promise(e).delay(t)},timeout:function(e,t){return this.promise(e).timeout(t)}},r,i=function(){if(typeof process=="object")return process.nextTick;if(e.setImmediate)return e.setImmediate;var t=[],n=function(){var e=t,n=0,r=t.length;t=[];while(n<r)e[n++]()};if(e.postMessage){var r=!0;if(e.attachEvent){var i=function(){r=!1};e.attachEvent("onmessage",i),e.postMessage("__checkAsync","*"),e.detachEvent("onmessage",i)}if(r){var s="__promise"+ +(new Date),o=function(e){e.data===s&&(e.stopPropagation&&e.stopPropagation(),n())};return e.addEventListener?e.addEventListener("message",o,!0):e.attachEvent("onmessage",o),function(n){t.push(n)===1&&e.postMessage(s,"*")}}}var u=e.document;if("onreadystatechange"in u.createElement("script")){var a=function(){var e=u.createElement("script");e.onreadystatechange=function(){e.parentNode.removeChild(e),e=e.onreadystatechange=null,n()},(u.documentElement||u.body).appendChild(e)};return function(e){t.push(e)===1&&a()}}return function(e){setTimeout(e,0)}}(),s=function(e){i(function(){throw e})},o=function(e){return typeof e=="function"},u=Array.prototype.slice,a=Object.prototype.toString,f=Array.isArray||function(e){return a.call(e)==="[object Array]"},l=function(e){var t=[],n=0,r=e.length;while(n<r)t.push(n++);return t},c=Object.keys||function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t};typeof exports=="object"?module.exports=n:typeof modules=="object"?modules.define("vow",function(e){e(n)}):typeof define=="function"?define(function(e,t,r){r.exports=n}):e.Vow=n})(this); | ||
* @version 0.3.3 | ||
*/(function(e){var t=function(e){this._res=e,this._isFulfilled=!!arguments.length,this._isRejected=!1,this._fulfilledCallbacks=[],this._rejectedCallbacks=[],this._progressCallbacks=[]};t.prototype={valueOf:function(){return this._res},isFulfilled:function(){return this._isFulfilled},isRejected:function(){return this._isRejected},isResolved:function(){return this._isFulfilled||this._isRejected},fulfill:function(e){if(this.isResolved())return;this._isFulfilled=!0,this._res=e,this._callCallbacks(this._fulfilledCallbacks,e),this._fulfilledCallbacks=this._rejectedCallbacks=this._progressCallbacks=r},reject:function(e){if(this.isResolved())return;this._isRejected=!0,this._res=e,this._callCallbacks(this._rejectedCallbacks,e),this._fulfilledCallbacks=this._rejectedCallbacks=this._progressCallbacks=r},notify:function(e){if(this.isResolved())return;this._callCallbacks(this._progressCallbacks,e)},then:function(e,n,i,s){n&&!o(n)?(s=n,n=r):i&&!o(i)&&(s=i,i=r);var u=new t,a;return this._isRejected||(a={promise:u,fn:o(e)?e:r,ctx:s},this._isFulfilled?this._callCallbacks([a],this._res):this._fulfilledCallbacks.push(a)),this._isFulfilled||(a={promise:u,fn:n,ctx:s},this._isRejected?this._callCallbacks([a],this._res):this._rejectedCallbacks.push(a)),this.isResolved()||this._progressCallbacks.push({promise:u,fn:i,ctx:s}),u},fail:function(e,t){return this.then(r,e,t)},always:function(e,t){var n=this,r=function(){return e(n)};return this.then(r,r,t)},progress:function(e,t){return this.then(r,r,e,t)},spread:function(e,t,n){return this.then(function(t){return e.apply(this,t)},t,n)},done:function(){this.fail(s)},delay:function(e){return this.then(function(n){var r=new t;return setTimeout(function(){r.fulfill(n)},e),r})},timeout:function(e){var n=new t,r=setTimeout(function(){n.reject(Error("timed out"))},e);return n.sync(this),n.always(function(){clearTimeout(r)}),n},sync:function(e){var t=this;e.then(function(e){t.fulfill(e)},function(e){t.reject(e)})},_callCallbacks:function(e,t){var r=e.length;if(!r)return;var s=this.isResolved(),o=this.isFulfilled();i(function(){var i=0,u,a,f;while(i<r){u=e[i++],a=u.promise,f=u.fn;if(f){var l=u.ctx,c;try{c=l?f.call(l,t):f(t)}catch(h){a.reject(h);continue}s?n.isPromise(c)?function(e){c.then(function(t){e.fulfill(t)},function(t){e.reject(t)})}(a):a.fulfill(c):a.notify(c)}else s?o?a.fulfill(t):a.reject(t):a.notify(t)}})}};var n={promise:function(e){return arguments.length?n.isPromise(e)?e:new t(e):new t},when:function(e,t,r,i,s){return n.promise(e).then(t,r,i,s)},fail:function(e,t,i){return n.when(e,r,t,i)},always:function(e,t,r){return n.promise(e).always(t,r)},progress:function(e,t,r){return n.promise(e).progress(t,r)},spread:function(e,t,r,i){return n.promise(e).spread(t,r,i)},done:function(e){n.isPromise(e)&&e.done()},isPromise:function(e){return e&&o(e.then)},valueOf:function(e){return n.isPromise(e)?e.valueOf():e},isFulfilled:function(e){return n.isPromise(e)?e.isFulfilled():!0},isRejected:function(e){return n.isPromise(e)?e.isRejected():!1},isResolved:function(e){return n.isPromise(e)?e.isResolved():!0},fulfill:function(e){return n.when(e,r,function(e){return e})},reject:function(e){return n.when(e,function(e){var n=new t;return n.reject(e),n})},resolve:function(e){return n.isPromise(e)?e:n.when(e)},invoke:function(e){try{return n.promise(e.apply(null,u.call(arguments,1)))}catch(t){return n.reject(t)}},forEach:function(e,t,r,i){var s=i?i.length:e.length,o=0;while(o<s)n.when(e[i?i[o]:o],t,r),++o},all:function(e){var r=new t,i=f(e),s=i?l(e):c(e),o=s.length,u=i?[]:{};if(!o)return r.fulfill(u),r;var a=o,h=function(){if(!--a){var t=0;while(t<o)u[s[t]]=n.valueOf(e[s[t++]]);r.fulfill(u)}},p=function(e){r.reject(e)};return n.forEach(e,h,p,s),r},allResolved:function(e){var r=new t,i=f(e),s=i?l(e):c(e),o=s.length,u=i?[]:{};if(!o)return r.fulfill(u),r;var a=function(){--o||r.fulfill(e)};return n.forEach(e,a,a,s),r},any:function(e){var r=new t,i=e.length;if(!i)return r.reject(Error()),r;var s=0,o,u=function(e){r.fulfill(e)},a=function(e){s||(o=e),++s===i&&r.reject(o)};return n.forEach(e,u,a),r},delay:function(e,t){return n.promise(e).delay(t)},timeout:function(e,t){return n.promise(e).timeout(t)}},r,i=function(){var t=[],n=function(e){return t.push(e)===1},r=function(){var e=t,n=0,r=t.length;t=[];while(n<r)e[n++]()};if(typeof process=="object")return function(e){n(e)&&process.nextTick(r)};if(e.setImmediate)return function(t){n(t)&&e.setImmediate(r)};if(e.postMessage){var i=!0;if(e.attachEvent){var s=function(){i=!1};e.attachEvent("onmessage",s),e.postMessage("__checkAsync","*"),e.detachEvent("onmessage",s)}if(i){var o="__promise"+ +(new Date),u=function(e){e.data===o&&(e.stopPropagation&&e.stopPropagation(),r())};return e.addEventListener?e.addEventListener("message",u,!0):e.attachEvent("onmessage",u),function(t){n(t)&&e.postMessage(o,"*")}}}var a=e.document;if("onreadystatechange"in a.createElement("script")){var f=function(){var e=a.createElement("script");e.onreadystatechange=function(){e.parentNode.removeChild(e),e=e.onreadystatechange=null,r()},(a.documentElement||a.body).appendChild(e)};return function(e){n(e)&&f()}}return function(e){n(e)&&setTimeout(r,0)}}(),s=function(e){i(function(){throw e})},o=function(e){return typeof e=="function"},u=Array.prototype.slice,a=Object.prototype.toString,f=Array.isArray||function(e){return a.call(e)==="[object Array]"},l=function(e){var t=[],n=0,r=e.length;while(n<r)t.push(n++);return t},c=Object.keys||function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t};typeof exports=="object"?module.exports=n:typeof modules=="object"?modules.define("vow",function(e){e(n)}):typeof define=="function"?define(function(e,t,r){r.exports=n}):e.Vow=n})(this); |
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
1245663
18348
344