Completed
Push — master ( 090c72...ff33da )
by Dylan
04:20 queued 01:54
created

js/crawler_event_handler.js   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 30
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 0
wmc 5
c 1
b 1
f 0
nc 1
mnd 2
bc 2
fnc 2
dl 0
loc 30
rs 10
bpm 1
cpm 2.5
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A crawler_event_handler.trigger 0 5 3
A crawler_event_handler.on 0 5 2
1
const crawler_event_handler = {
2
3
    events : {},
4
5
    /**
6
     * Trigger event callback and pass on the data
7
     *
8
     * @param {string} event
9
     * @param {*} data
10
     * @returns {undefined}
11
     */
12
    trigger: function(event, data){
13
        if(this.events.hasOwnProperty(event))
14
            for(var e in this.events[event]) this.events[event][e].apply(this, data);
15
        return undefined;
16
    },
17
18
    /**
19
     * Register callback on action
20
     *
21
     * @param {string} event
22
     * @param {function} callback
23
     * @returns {undefined}
24
     */
25
    on: function(event, callback){
26
        if(!this.events.hasOwnProperty(event)) this.events[event] = [];
27
        this.events[event].push(callback);
28
        return undefined;
29
    },
30
};
31