https://github.com/lightsofapollo/middleware-object-hooks
(Promise based) Object middleware
https://github.com/lightsofapollo/middleware-object-hooks
Last synced: 8 months ago
JSON representation
(Promise based) Object middleware
- Host: GitHub
- URL: https://github.com/lightsofapollo/middleware-object-hooks
- Owner: lightsofapollo
- License: other
- Created: 2014-02-05T00:07:48.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-05-06T05:03:25.000Z (about 11 years ago)
- Last Synced: 2025-01-27T18:52:13.816Z (over 1 year ago)
- Language: JavaScript
- Size: 422 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# middleware-object-hooks
[](https://travis-ci.org/lightsofapollo/middleware-object-hooks)
Middleware(ish) hooks based on "methods" in objects.
## Usage
(Also see [examples/](examples/))
```js
var middleware = require('middleware-object-hooks');
middlware.use({
start: function(value) {
value.calls = value.calls || 0;
return value;
}
});
middlware.use({
start: function(value) {
value.calls++;
}
});
middlware.use({
start: function() {
return new Promise(function(accept, reject) {
// do some magic then accept / reject
});
}
});
middlware.run(
'start', // method in the middleware
{
// passed to the method in the middleware
}
).then(
function(value) {
},
function(err) {
}
);
```
## Notes
- Middleware methods are invoked within the context of their object
- Multiple values may be passed to run (or none at all)
- Each result is passed directly to the next middleware so its possible
to both mutate the value (if its an object) and entirely replace it.