middlewarify
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -114,9 +114,11 @@ /** | ||
var midd = midds.shift(); | ||
Promise.try(function(){return midd.apply(null, args);}) | ||
// Promise.try(function(){return midd.apply(null, args);}) | ||
Promise.try(midd.bind.apply(midd, [null].concat(args))) | ||
.then(function(val) { | ||
if (midd.isMain) { | ||
store.mainCallbackReturnValue = val; | ||
args.push(val); | ||
} | ||
middlewarify._fetchAndInvoke(midds, args, deferred, store); | ||
},deferred.reject.bind(deferred)); | ||
}, deferred.reject.bind(deferred)); | ||
}; | ||
@@ -136,3 +138,2 @@ | ||
var middlewares = Array.prototype.slice.call(arguments, 2); | ||
var len = middlewares.length; | ||
@@ -139,0 +140,0 @@ if (len === 0) return; |
{ | ||
"name": "middlewarify", | ||
"description": "Apply the middleware pattern to any function.", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"homepage": "https://github.com/thanpolas/middlewarify", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -189,3 +189,3 @@ # Middlewarify | ||
All middleware get invoked with the arguments that the *Middleware Container* was invoked with. The same number or arguments, the exact same references. | ||
All middleware gets invoked with the arguments that the *Middleware Container* was invoked with. The same number or arguments, the exact same references. | ||
@@ -256,3 +256,23 @@ ```js | ||
``` | ||
#### After Hooks get the Result too | ||
If your middleware if a Before / After type, then all `.after()` hooks will receive an extra argument representing the resolving value. | ||
```js | ||
middlewarify.make(crud, 'create', function(arg1, arg2) { | ||
return 'abc'; | ||
}); | ||
crud.create.after(function(arg1, arg2, val) { | ||
console.log(val); // prints 'abc' | ||
}); | ||
crud.create(1, 2); | ||
``` | ||
## Release History | ||
- **v0.3.3**, *15 Feb 2014* | ||
- Resolving value now gets propagated to all `.after()` hooks. | ||
- **v0.3.2**, *09 Feb 2014* | ||
@@ -259,0 +279,0 @@ - Optimize middleware invocation using `Promise.try()` |
@@ -217,1 +217,31 @@ /** | ||
}); | ||
suite('6.6. Resolving Value propagation to After middl', function(){ | ||
var obj; | ||
setup(function(){ | ||
obj = Object.create(null); | ||
}); | ||
test('6.6.1 resolving value gets passed as an extra argument by promise', function(done) { | ||
midd.make(obj, 'create', function() { | ||
return new Promise(function(resolve) { | ||
setTimeout(function(){ | ||
resolve('abc'); | ||
}); | ||
}); | ||
},{beforeAfter: true}); | ||
obj.create.after(function(arg1, arg2, resolveValue) { | ||
assert.equal(resolveValue, 'abc'); | ||
}); | ||
obj.create(1, 2).then(done.bind(null, null), done); | ||
}); | ||
test('6.6.2 resolving value gets passed as an extra argument by returning', function(done) { | ||
midd.make(obj, 'create', function() { | ||
return 'abc'; | ||
}, {beforeAfter: true}); | ||
obj.create.after(function(arg1, arg2, resolveValue) { | ||
assert.equal(resolveValue, 'abc'); | ||
}); | ||
obj.create(1, 2).then(done.bind(null, null), done); | ||
}); | ||
}); |
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
40122
806
305