1 | # Hookable
|
2 |
|
3 | Enable hookable functions on an object.
|
4 |
|
5 | [![Build Status](https://secure.travis-ci.org/RGBboy/hookable.png)](http://travis-ci.org/RGBboy/hookable)
|
6 |
|
7 | ## Installation
|
8 |
|
9 | Works with Express 3.0.x
|
10 |
|
11 | $ npm install hookable
|
12 |
|
13 | ## Usage
|
14 |
|
15 | Hookable adds functionality to wrap a function with `before` and `after` hooks
|
16 |
|
17 | ``` javascript
|
18 |
|
19 | // require it
|
20 | var hookable = require('hookable'),
|
21 | myObject = {
|
22 | add: function (a, b) {
|
23 | return a + b;
|
24 | }
|
25 | };
|
26 |
|
27 | // use it on your object
|
28 | hookable(myObject);
|
29 |
|
30 | // enable hooking on your objects function
|
31 | myObject.add = myObject.hook('add', myObject.add);
|
32 |
|
33 | // define a function to fire before the original
|
34 | myObject.before('add', function (a, b) {
|
35 | console.log('.add is about to fire with ' + a + ' and ' + b);
|
36 | });
|
37 |
|
38 | // define a function to fire after the original
|
39 | myObject.after('add', function (a, b) {
|
40 | console.log('.add has fired with ' + a + ' and ' + b);
|
41 | });
|
42 | ```
|
43 |
|
44 | ## To Do
|
45 |
|
46 | * Make hooks fire asynchronously
|
47 | * Write tests
|