Comparing version 0.2.2 to 0.2.3
@@ -28,3 +28,3 @@ /*! | ||
*/ | ||
exports.version = '0.2.2'; | ||
exports.version = '0.2.3'; | ||
@@ -156,2 +156,26 @@ /** | ||
/** | ||
* # Oath.node(err, [...]) | ||
* | ||
* Provides a node-able function... | ||
* Works, provided the expectation is that | ||
* if there was an error, it will be returned | ||
* as the first argument. | ||
* | ||
* var oath = new Oath(); | ||
* fs.mkdir(dir, oath.node()); | ||
* | ||
* @name Oath.node | ||
* @return {Function} expection function (err, data) { ... | ||
*/ | ||
Oath.prototype.node = function () { | ||
var self = this; | ||
return function () { | ||
if (arguments[0]) return self.reject(arguments[0]); | ||
var args = Array.prototype.slice.call(arguments, 1, arguments.length) | ||
self.resolve.apply(self, args); | ||
} | ||
}; | ||
/** | ||
* # .then([success], [failure]) | ||
@@ -158,0 +182,0 @@ * |
@@ -7,2 +7,2 @@ /*! | ||
!function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("oath",function(){function c(a){a=a||{},this._pending={},this._oath={complete:!1,context:a.context||this};var b=this;this.promise={then:function(a,c,d){return a&&b._register("resolve",a),c&&b._register("reject",c),d&&b._register("progress",d),b._oath.complete&&b._traverse(),this},onprogress:function(a){return b._register("progress",a),this},node:function(a){return this.then(function(b){a(null,b)},function(b){a(b)}),this}}}if(!a)var a={};var b=a.exports=c;return b.version="0.2.2",c.prototype.resolve=function(a){this._fulfill("resolve",a)},c.prototype.reject=function(a){this._fulfill("reject",a)},c.prototype.progress=function(a){var b=this._pending.progress;if(!b)return!1;for(var c=0;c<b.length;c++)b[c](a)},c.prototype._register=function(a,b){var c=this._oath.context,d=this._pending[a],e;if(b.length<2)e=function(a){return b.call(c,a)};else if(b.length==2)e=function(a,d){b.call(c,a,d)};else throw new Error("Oath: Invalid function registered - to many parameters.");d?d.push(e):this._pending[a]=[e]},c.prototype._fulfill=function(a,b){if(this._oath.complete)return!1;this._oath.complete={type:a,result:b},this._traverse()},c.prototype._traverse=function(){var a=this,b=this._oath.context,c=this._oath.complete.type;if(!this._pending[c])return!1;var d=function(){var b=a._pending[c].shift(),e=a._oath.complete.result;if(b.length<2){var f=b(e);f&&(a._oath.complete.result=f),a._pending[c].length&&d()}else{var g=function(b){b&&(a._oath.complete.result=b),a._pending[c].length&&d()};b(e,g)}};d()},b}) | ||
!function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("oath",function(){function c(a){a=a||{},this._pending={},this._oath={complete:!1,context:a.context||this};var b=this;this.promise={then:function(a,c,d){return a&&b._register("resolve",a),c&&b._register("reject",c),d&&b._register("progress",d),b._oath.complete&&b._traverse(),this},onprogress:function(a){return b._register("progress",a),this},node:function(a){return this.then(function(b){a(null,b)},function(b){a(b)}),this}}}if(!a)var a={};var b=a.exports=c;return b.version="0.2.3",c.prototype.resolve=function(a){this._fulfill("resolve",a)},c.prototype.reject=function(a){this._fulfill("reject",a)},c.prototype.progress=function(a){var b=this._pending.progress;if(!b)return!1;for(var c=0;c<b.length;c++)b[c](a)},c.prototype.node=function(){var a=this;return function(){if(arguments[0])return a.reject(arguments[0]);var b=Array.prototype.slice.call(arguments,1,arguments.length);a.resolve.apply(a,b)}},c.prototype._register=function(a,b){var c=this._oath.context,d=this._pending[a],e;if(b.length<2)e=function(a){return b.call(c,a)};else if(b.length==2)e=function(a,d){b.call(c,a,d)};else throw new Error("Oath: Invalid function registered - to many parameters.");d?d.push(e):this._pending[a]=[e]},c.prototype._fulfill=function(a,b){if(this._oath.complete)return!1;this._oath.complete={type:a,result:b},this._traverse()},c.prototype._traverse=function(){var a=this,b=this._oath.context,c=this._oath.complete.type;if(!this._pending[c])return!1;var d=function(){var b=a._pending[c].shift(),e=a._oath.complete.result;if(b.length<2){var f=b(e);f&&(a._oath.complete.result=f),a._pending[c].length&&d()}else{var g=function(b){b&&(a._oath.complete.result=b),a._pending[c].length&&d()};b(e,g)}};d()},b}) |
0.2.3 / 2012-01-30 | ||
================== | ||
* added internal api Oath#node as helper for quick reject/resolve with node style callbacks | ||
* changed test reporter | ||
0.2.2 / 2012-01-29 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -13,3 +13,3 @@ /*! | ||
*/ | ||
exports.version = '0.2.2'; | ||
exports.version = '0.2.3'; | ||
@@ -141,2 +141,26 @@ /** | ||
/** | ||
* # Oath.node(err, [...]) | ||
* | ||
* Provides a node-able function... | ||
* Works, provided the expectation is that | ||
* if there was an error, it will be returned | ||
* as the first argument. | ||
* | ||
* var oath = new Oath(); | ||
* fs.mkdir(dir, oath.node()); | ||
* | ||
* @name Oath.node | ||
* @return {Function} expection function (err, data) { ... | ||
*/ | ||
Oath.prototype.node = function () { | ||
var self = this; | ||
return function () { | ||
if (arguments[0]) return self.reject(arguments[0]); | ||
var args = Array.prototype.slice.call(arguments, 1, arguments.length) | ||
self.resolve.apply(self, args); | ||
} | ||
}; | ||
/** | ||
* # .then([success], [failure]) | ||
@@ -143,0 +167,0 @@ * |
@@ -5,3 +5,3 @@ { | ||
"description": "Tiny library for node and the browser that makes it easy to build and interact with promise/future based APIs.", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"homepage": "http://alogicalparadox.com/oath", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -256,2 +256,47 @@ if (!chai) | ||
}); | ||
describe('internal node callback helper', function (done) { | ||
it('should work on failure', function (done) { | ||
var doctor = new oath(); | ||
var success = function (a, b) { | ||
expect(true).to.be.false; | ||
} | ||
var failure = function (e) { | ||
expect(e).to.be.instanceof(Error); | ||
expect(arguments).to.have.length(1); | ||
done(); | ||
} | ||
function depart (some, cb) { | ||
cb(new Error('No companion aboard. Dont leave!')); | ||
} | ||
doctor.promise.then(success, failure); | ||
depart('now', doctor.node()); | ||
}); | ||
it('should work on success', function (done) { | ||
var doctor = new oath(); | ||
var success = function (res) { | ||
expect(arguments).to.have.length(1); | ||
expect(res).to.be.instanceof(Array); | ||
expect(res).to.eql([ 'k9', 'sj' ]); | ||
done(); | ||
} | ||
var failure = function (e) { | ||
expect(false).to.be.true; | ||
} | ||
function depart (some, cb) { | ||
cb(null, ['k9', 'sj' ]); | ||
} | ||
doctor.promise.then(success, failure); | ||
depart('now', doctor.node()); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
35236
776