Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 43 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | // jshint esversion: 8 |
||
3 | var debug = require('debug')('main.bw.auxiliary'); |
||
4 | |||
5 | /* |
||
6 | resetUiCounters |
||
7 | Reset bulk whois UI counters to their initial values |
||
8 | parameters |
||
9 | event (object) - renderer object |
||
10 | */ |
||
11 | function resetUiCounters(event) { |
||
12 | var { |
||
13 | sender |
||
14 | } = event; |
||
15 | |||
16 | debug("Resetting bulk whois UI counters"); |
||
17 | |||
18 | var baseValues = { |
||
19 | integer: 0, |
||
20 | string: '-' |
||
21 | }, |
||
22 | events = { |
||
23 | integer: [ |
||
24 | 'time.current', 'time.remaining', // Timers |
||
25 | 'laststatus.available', 'laststatus.unavailable', 'laststatus.error' // Last domain status |
||
26 | ], |
||
27 | string: [ |
||
28 | 'domains.total', 'domains.waiting', 'domains.sent', 'domains.processed', // Domains |
||
29 | 'reqtimes.maximum', 'reqtimes.minimum', 'reqtimes.last', 'reqtimes.average', // Request times |
||
30 | 'status.available', 'status.unavailable', 'status.error' // Number stats |
||
31 | ] |
||
32 | }, |
||
33 | channel = 'bw:status.update'; |
||
34 | |||
35 | // Loop through events and send default values |
||
36 | for (var eventType in events) |
||
|
|||
37 | for (var listedEvent in events[eventType]) |
||
38 | sender.send(channel, events[eventType][listedEvent], baseValues[eventType]); |
||
39 | |||
40 | } |
||
41 | |||
42 | module.exports = { |
||
43 | resetUiCounters: resetUiCounters, |
||
44 | rstUiCntrs: resetUiCounters |
||
45 | }; |
||
46 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: