-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (35 loc) · 1021 Bytes
/
index.js
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
37
38
39
var _ = require("underscore")
module.exports = function(plasma, dna){
this.dna = dna
this.dna.methods = dna.methods || ["log", "debug", "error", "warn", "info", "trace"]
this.methods = []
this.plasma = plasma
if(dna.reactOn)
plasma.on(dna.reactOn, this.reaction, this)
else
this.reaction(dna)
if(dna.disposeOn)
plasma.on(dna.disposeOn, this.dispose, this)
}
module.exports.prototype.reaction = function(options) {
var self = this
this.dna.methods.forEach(function(method){
self.methods[method] = console[method]
console[method] = function(){
self.emitEvery({
method: method,
arguments: Array.prototype.slice.call(arguments, 0)
})
}
})
}
module.exports.prototype.dispose = function(options) {
var self = this
this.dna.methods.forEach(function(method){
if(self.methods[method])
console[method] = self.methods[method]
})
}
module.exports.prototype.emitEvery = function(c) {
this.plasma.emit(_.extend({}, this.dna.emitEvery, c))
}