gangvy 53eee08a2f update 5 ماه پیش
..
test 53eee08a2f update 5 ماه پیش
.npmignore 53eee08a2f update 5 ماه پیش
History.md 53eee08a2f update 5 ماه پیش
Makefile 53eee08a2f update 5 ماه پیش
Readme.md 53eee08a2f update 5 ماه پیش
example.js 53eee08a2f update 5 ماه پیش
index.js 53eee08a2f update 5 ماه پیش
package.json 53eee08a2f update 5 ماه پیش

Readme.md

before

before decorator factory

Installation

npm install before

Example

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