-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (31 loc) · 807 Bytes
/
index.js
File metadata and controls
36 lines (31 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var ware = require('ware');
module.exports = function() {
this.hooks = {};
this.hook = function(name, fn) {
name = '$' + name;
return this.use(function() {
this.hooks[name] = this.hooks[name] || [];
this.hooks[name].push(fn);
});
};
this.prototype.run = function(name, cb) {
name = '$' + name;
createPipeline(this.model.hooks[name]).run(this, cb);
};
this.prototype.runRecursively = function(name, cb) {
var self = this;
this.eachAttrAsync(function(attr, type, next) {
self.get(attr).runRecursively(name, next);
}, function(err) {
if(err) return cb(err);
self.run(name, cb);
});
};
function createPipeline(fns) {
var mw = ware();
(fns || []).forEach(function(fn) {
mw.use(fn);
});
return mw;
}
};