Comparing version 0.0.1 to 0.1.0
@@ -36,24 +36,11 @@ | ||
/** | ||
* Return a function for input and callback | ||
* Call back a function from the given input. | ||
*/ | ||
Ware.prototype.end = function () { | ||
Ware.prototype.end = function (input, callback) { | ||
var fns = this.fns | ||
, errFn = this.errFn; | ||
return function (input, callback) { | ||
iter(fns, errFn, input, callback); | ||
}; | ||
}; | ||
return next(0, {}); | ||
/** | ||
* Iterate over the middleware functions. Uses an object for the default output | ||
* or you can pass your own. | ||
*/ | ||
function iter (fns, errFn, input, callback) { | ||
next(0, {}); | ||
function next (index, output) { | ||
@@ -68,2 +55,2 @@ var fn = fns[index]; | ||
} | ||
} | ||
}; |
{ | ||
"name": "ware", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Generic middleware to compose a series of functions", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,13 +10,10 @@ | ||
var Ware = require('ware'); | ||
var ware = require('ware')(); | ||
var middleware = new Ware() | ||
.use(function (input, output, next) { | ||
output.x = input.x * 2; | ||
next(); | ||
}); | ||
ware.use(function (input, output, next) { | ||
output.x = input.x * 2; | ||
next(); | ||
}); | ||
var composed = middleware.end(); | ||
composed({ x : 4 }, function (err, result) { | ||
ware.end({ x : 4 }, function (err, result) { | ||
console.log(result.x); // 8 | ||
@@ -43,10 +40,8 @@ }); | ||
#### .end() | ||
#### .end(input, fn) | ||
Returns a function which composes all the middleware. | ||
Runs the middleware functions. | ||
```javascript | ||
var composed = ware.end(); | ||
composed(input, function (err, result) { /*...*/ }); | ||
ware.end(input, function (err, result) { /*...*/ }); | ||
``` | ||
@@ -53,0 +48,0 @@ |
3751
55
70