Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stagas/before
before decorator factory
https://github.com/stagas/before
Last synced: 14 days ago
JSON representation
before decorator factory
- Host: GitHub
- URL: https://github.com/stagas/before
- Owner: stagas
- Created: 2013-11-21T22:01:50.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2013-11-21T22:02:16.000Z (almost 11 years ago)
- Last Synced: 2024-09-17T00:05:18.660Z (about 2 months ago)
- Language: JavaScript
- Size: 85.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# before
before decorator factory
## Installation
`npm install before`
## Example
```js
var before = require('before');// an object with some method
var speak = {
greeting: 'welcome',
greet: function(a, b, fn){
fn(null, a + ' ' + b);
}
};// factory before hook method
speak.before = before(speak);// before greet
speak.before('greet', function(args, fn){
args[0] = args[0] + ' to this wonderful';
fn();
});// one more, this will run first
speak.before('greet', function(args, fn){
args[0] = args[0] + ', ' + this.greeting;
fn();
});// runs mutation hooks, then greets
speak.greet('Human', 'world!', function(err, result){
console.log(result); // => Human, welcome to this wonderful world!
});
```## API
### before(context)
Captures `context` to be used by decorator.
### before(method, outer)
Decorates `method` using `outer`.
`outer` is called with `(args, fn)` to allow
arguments mutation.## License
MIT