-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgoblin.js
40 lines (33 loc) · 883 Bytes
/
goblin.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
40
const EventEmitter = require('events');
const _ = require('lodash');
const configGoblin = require('../config');
const errors = require('./logger/errors');
const goblin = {
config: configGoblin,
db: {},
goblinDataEmitter: new EventEmitter(),
ambush: [],
ambushEmitter: new EventEmitter(),
hooks: {
add: addHook,
remove: removeHook,
repository: []
},
errorEmitter: new EventEmitter(),
saveDataTask: undefined
};
function addHook(event, callback){
if(event && typeof(event) === 'string' && callback && typeof(callback) === 'function') {
goblin.hooks.repository.push({event, callback});
} else {
throw configGoblin.logPrefix, errors.EVENT_RECORD;
}
}
function removeHook(event, callback) {
const searchObj = {event};
if (callback !== undefined) {
searchObj.callback = callback;
}
_.remove(goblin.hooks.repository, searchObj);
}
module.exports = goblin;