Completed
Push — master ( 8967bc...e88c19 )
by Rain
02:47
created

AbstracCheckbox.js ➔ ... ➔ ???   F

Complexity

Conditions 13
Paths 432

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 13
c 2
b 0
f 0
nc 432
nop 1
dl 0
loc 31
rs 3.6036

How to fix   Complexity   

Complexity

Complex classes like AbstracCheckbox.js ➔ ... ➔ ??? often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
2
import ko from 'ko';
3
import {isUnd} from 'Common/Utils';
4
import {AbstractComponent} from 'Component/Abstract';
5
6
class AbstracCheckbox extends AbstractComponent
7
{
8
	/**
9
	 * @constructor
10
	 * @param {Object} params = {}
11
	 */
12
	constructor(params = {}) {
13
14
		super();
15
16
		this.value = params.value;
17
		if (isUnd(this.value) || !this.value.subscribe)
18
		{
19
			this.value = ko.observable(isUnd(this.value) ? false : !!this.value);
20
		}
21
22
		this.enable = params.enable;
23
		if (isUnd(this.enable) || !this.enable.subscribe)
24
		{
25
			this.enable = ko.observable(isUnd(this.enable) ? true : !!this.enable);
26
		}
27
28
		this.disable = params.disable;
29
		if (isUnd(this.disable) || !this.disable.subscribe)
30
		{
31
			this.disable = ko.observable(isUnd(this.disable) ? false : !!this.disable);
32
		}
33
34
		this.label = params.label || '';
35
		this.inline = isUnd(params.inline) ? false : params.inline;
36
37
		this.readOnly = isUnd(params.readOnly) ? false : !!params.readOnly;
38
		this.inverted = isUnd(params.inverted) ? false : !!params.inverted;
39
40
		this.labeled = !isUnd(params.label);
41
		this.labelAnimated = !!params.labelAnimated;
42
	}
43
44
	click() {
45
		if (!this.readOnly && this.enable() && !this.disable())
46
		{
47
			this.value(!this.value());
48
		}
49
	}
50
}
51
52
export {AbstracCheckbox, AbstracCheckbox as default};
53