simply-deferred
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -237,3 +237,3 @@ // Generated by CoffeeScript 1.6.3 | ||
}); | ||
return it('should accept promises from filters and call them later with arguments', function(done) { | ||
it('should accept promises from filters and call them later with arguments', function(done) { | ||
var def, filter; | ||
@@ -258,2 +258,15 @@ def = deferred.Deferred(); | ||
}); | ||
return it('should allow changing the state', function(done) { | ||
var def; | ||
def = deferred.Deferred(); | ||
def.pipe(function(result) { | ||
return deferred.Deferred().reject('failure').promise(); | ||
}).fail(function(msg) { | ||
assert.equal(msg, 'failure'); | ||
if (msg === 'failure') { | ||
return done(); | ||
} | ||
}); | ||
return def.resolve('r1'); | ||
}); | ||
}); | ||
@@ -343,2 +356,3 @@ describe('then', function() { | ||
after_all = deferred.when(d1); | ||
assert.equal(d1, after_all); | ||
after_all.done(function(arg1) { | ||
@@ -345,0 +359,0 @@ if (arg1 === 42) { |
@@ -6,3 +6,3 @@ // Generated by CoffeeScript 1.6.3 | ||
VERSION = '2.3.0'; | ||
VERSION = '2.4.0'; | ||
@@ -107,31 +107,22 @@ PENDING = "pending"; | ||
pipe = function(doneFilter, failFilter) { | ||
var deferred, filter; | ||
deferred = new Deferred(); | ||
filter = function(source, destination, filter) { | ||
if (filter) { | ||
return candidate[source](function() { | ||
var args, filteredArgs; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
filteredArgs = filter.apply(null, args); | ||
if (isPromise(filteredArgs)) { | ||
return filteredArgs[source](function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
return destination.apply(null, args); | ||
}); | ||
} else { | ||
return destination(filteredArgs); | ||
} | ||
}); | ||
} else { | ||
return candidate[source](function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
return destination.apply(null, args); | ||
}); | ||
var filter, master; | ||
master = new Deferred(); | ||
filter = function(source, funnel, callback) { | ||
if (!callback) { | ||
return candidate[source](master[funnel]); | ||
} | ||
return candidate[source](function() { | ||
var args, value; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
value = callback.apply(null, args); | ||
if (isPromise(value)) { | ||
return value.done(master.resolve).fail(master.reject); | ||
} else { | ||
return master[funnel](value); | ||
} | ||
}); | ||
}; | ||
filter('done', deferred.resolve, doneFilter); | ||
filter('fail', deferred.reject, failFilter); | ||
return deferred; | ||
filter('done', 'resolve', doneFilter); | ||
filter('fail', 'reject', failFilter); | ||
return master; | ||
}; | ||
@@ -174,2 +165,9 @@ candidate.pipe = pipe; | ||
defs = flatten(arguments); | ||
if (defs.length === 1) { | ||
if (isPromise(defs[0])) { | ||
return defs[0]; | ||
} else { | ||
return (new Deferred()).resolve(defs[0]).promise(); | ||
} | ||
} | ||
trigger = new Deferred(); | ||
@@ -241,2 +239,12 @@ if (!defs.length) { | ||
exports.installInto = installInto; | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(function() { | ||
if (Zepto) { | ||
return installInto(Zepto); | ||
} else { | ||
return Deferred; | ||
} | ||
}); | ||
} else if (Zepto) { | ||
installInto(Zepto); | ||
} else { | ||
@@ -243,0 +251,0 @@ this.Deferred = function() { |
@@ -1,1 +0,1 @@ | ||
!function(){var n,r,e,t,u,l,o,i,a,c,s,f,p,h,g=[].slice;u="2.3.0",r="pending",t="resolved",e="rejected",a=function(n,r){return null!=n?n.hasOwnProperty(r):void 0},s=function(n){return a(n,"length")&&a(n,"callee")},f=function(n){return a(n,"promise")&&"function"==typeof(null!=n?n.promise:void 0)},i=function(n){return s(n)?i(Array.prototype.slice.call(n)):Array.isArray(n)?n.reduce(function(n,r){return Array.isArray(r)?n.concat(i(r)):(n.push(r),n)},[]):[n]},l=function(n,r){return 0>=n?r():function(){return--n<1?r.apply(this,arguments):void 0}},p=function(n,r){return function(){var e;return e=[n].concat(Array.prototype.slice.call(arguments,0)),r.apply(this,e)}},o=function(n,r,e){var t,u,l,o,a;for(o=i(n),a=[],u=0,l=o.length;l>u;u++)t=o[u],a.push(t.call.apply(t,[e].concat(g.call(r))));return a},n=function(){var u,l,a,c,s,p;return p=r,c=[],s=[],a={},this.promise=function(u){var l,h;return u=u||{},u.state=function(){return p},h=function(n,e){return function(){return p===r&&e.push.apply(e,i(arguments)),n()&&o(arguments,a),u}},u.done=h(function(){return p===t},c),u.fail=h(function(){return p===e},s),u.always=function(){var n;return(n=u.done.apply(u,arguments)).fail.apply(n,arguments)},l=function(r,e){var t,l;return t=new n,l=function(n,r,e){return e?u[n](function(){var t,u;return t=1<=arguments.length?g.call(arguments,0):[],u=e.apply(null,t),f(u)?u[n](function(){var n;return n=1<=arguments.length?g.call(arguments,0):[],r.apply(null,n)}):r(u)}):u[n](function(){var n;return n=1<=arguments.length?g.call(arguments,0):[],r.apply(null,n)})},l("done",t.resolve,r),l("fail",t.reject,e),t},u.pipe=l,u.then=l,null==u.promise&&(u.promise=function(){return u}),u},this.promise(this),u=this,l=function(n,e,t){return function(){return p===r?(p=n,a=arguments,o(e,a,t),u):this}},this.resolve=l(t,c),this.reject=l(e,s),this.resolveWith=function(n,r){return l(t,c,n).apply(null,r)},this.rejectWith=function(n,r){return l(e,s,n).apply(null,r)},this},h=function(){var r,e,t,u,o,a,c;if(e=i(arguments),o=new n,!e.length)return o.resolve().promise();for(u=[],t=l(e.length,function(){return o.resolve.apply(o,u)}),e.forEach(function(n,r){return f(n)?n.done(function(){var n;return n=1<=arguments.length?g.call(arguments,0):[],u[r]=n.length>1?n:n[0],t()}):(u[r]=n,t())}),a=0,c=e.length;c>a;a++)r=e[a],f(r)&&r.fail(o.reject);return o.promise()},c=function(r){return r.Deferred=function(){return new n},r.ajax=p(r.ajax,function(r,e){var t,u,l,o;return null==e&&(e={}),u=new n,t=function(n,r){return p(n,function(){var n,e;return e=arguments[0],n=2<=arguments.length?g.call(arguments,1):[],e&&e.apply(null,n),r.apply(null,n)})},e.success=t(e.success,u.resolve),e.error=t(e.error,u.reject),o=r(e),l=u.promise(),l.abort=function(){return o.abort()},l}),r.when=h},"undefined"!=typeof exports?(exports.Deferred=function(){return new n},exports.when=h,exports.installInto=c):(this.Deferred=function(){return new n},this.Deferred.when=h,this.Deferred.installInto=c)}.call(this); | ||
!function(){var n,r,e,t,u,o,i,l,a,c,s,f,p,h,g=[].slice;u="2.4.0",r="pending",t="resolved",e="rejected",a=function(n,r){return null!=n?n.hasOwnProperty(r):void 0},s=function(n){return a(n,"length")&&a(n,"callee")},f=function(n){return a(n,"promise")&&"function"==typeof(null!=n?n.promise:void 0)},l=function(n){return s(n)?l(Array.prototype.slice.call(n)):Array.isArray(n)?n.reduce(function(n,r){return Array.isArray(r)?n.concat(l(r)):(n.push(r),n)},[]):[n]},o=function(n,r){return 0>=n?r():function(){return--n<1?r.apply(this,arguments):void 0}},p=function(n,r){return function(){var e;return e=[n].concat(Array.prototype.slice.call(arguments,0)),r.apply(this,e)}},i=function(n,r,e){var t,u,o,i,a;for(i=l(n),a=[],u=0,o=i.length;o>u;u++)t=i[u],a.push(t.call.apply(t,[e].concat(g.call(r))));return a},n=function(){var u,o,a,c,s,p;return p=r,c=[],s=[],a={},this.promise=function(u){var o,h;return u=u||{},u.state=function(){return p},h=function(n,e){return function(){return p===r&&e.push.apply(e,l(arguments)),n()&&i(arguments,a),u}},u.done=h(function(){return p===t},c),u.fail=h(function(){return p===e},s),u.always=function(){var n;return(n=u.done.apply(u,arguments)).fail.apply(n,arguments)},o=function(r,e){var t,o;return o=new n,t=function(n,r,e){return e?u[n](function(){var n,t;return n=1<=arguments.length?g.call(arguments,0):[],t=e.apply(null,n),f(t)?t.done(o.resolve).fail(o.reject):o[r](t)}):u[n](o[r])},t("done","resolve",r),t("fail","reject",e),o},u.pipe=o,u.then=o,null==u.promise&&(u.promise=function(){return u}),u},this.promise(this),u=this,o=function(n,e,t){return function(){return p===r?(p=n,a=arguments,i(e,a,t),u):this}},this.resolve=o(t,c),this.reject=o(e,s),this.resolveWith=function(n,r){return o(t,c,n).apply(null,r)},this.rejectWith=function(n,r){return o(e,s,n).apply(null,r)},this},h=function(){var r,e,t,u,i,a,c;if(e=l(arguments),1===e.length)return f(e[0])?e[0]:(new n).resolve(e[0]).promise();if(i=new n,!e.length)return i.resolve().promise();for(u=[],t=o(e.length,function(){return i.resolve.apply(i,u)}),e.forEach(function(n,r){return f(n)?n.done(function(){var n;return n=1<=arguments.length?g.call(arguments,0):[],u[r]=n.length>1?n:n[0],t()}):(u[r]=n,t())}),a=0,c=e.length;c>a;a++)r=e[a],f(r)&&r.fail(i.reject);return i.promise()},c=function(r){return r.Deferred=function(){return new n},r.ajax=p(r.ajax,function(r,e){var t,u,o,i;return null==e&&(e={}),u=new n,t=function(n,r){return p(n,function(){var n,e;return e=arguments[0],n=2<=arguments.length?g.call(arguments,1):[],e&&e.apply(null,n),r.apply(null,n)})},e.success=t(e.success,u.resolve),e.error=t(e.error,u.reject),i=r(e),o=u.promise(),o.abort=function(){return i.abort()},o}),r.when=h},"undefined"!=typeof exports?(exports.Deferred=function(){return new n},exports.when=h,exports.installInto=c):"function"==typeof define&&define.amd?define(function(){return Zepto?c(Zepto):n}):Zepto?c(Zepto):(this.Deferred=function(){return new n},this.Deferred.when=h,this.Deferred.installInto=c)}.call(this); |
@@ -5,3 +5,3 @@ { | ||
"description": "A deferred library for Node.js and the browser with a simplified jQuery compatible API", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"homepage": "http://sudhirj.github.com/simply-deferred/", | ||
@@ -8,0 +8,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
50780
720