Lines of Code | 40 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const ssn = require('short-string-number'); |
||
2 | |||
3 | const config = require('./../configs/main'); |
||
4 | |||
5 | /** |
||
6 | * Counter - is class which calculates count of received messages |
||
7 | * and shows current count value in counter block. |
||
8 | */ |
||
9 | class Counter { |
||
10 | /** |
||
11 | * Counter's constructor. |
||
12 | */ |
||
13 | constructor() { |
||
14 | this.count = 0; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Increments counter value. |
||
19 | */ |
||
20 | inc() { |
||
21 | this.count += 1; |
||
22 | |||
23 | this.showCount(); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Renders current counter value counter block. |
||
28 | */ |
||
29 | showCount() { |
||
30 | const c = ssn(this.count); |
||
31 | document.getElementById('counter').innerHTML = typeof c === 'number' ? c.toString() : c; |
||
32 | document.getElementById('counterPrecise').innerHTML = this.count.toString(); |
||
33 | |||
34 | if (this.count >= config.thresholdToDisplayCounter) { |
||
35 | document.getElementById('counterBlock').style.display = 'block'; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | module.exports = new Counter(); |
||
41 |