1
+ // prettier-ignore
1
2
export class StepBuilder {
2
3
/**
3
4
* Main class for building the Step structure
4
5
*/
5
6
6
- constructor ( ) {
7
+ constructor ( ) {
7
8
this . start = 1 ;
8
9
this . current = 1 ;
9
10
this . size = null ;
@@ -13,16 +14,16 @@ export class StepBuilder {
13
14
* @param {Array } steps - Array of step titles
14
15
* @return {Array } Returns an array of connected steps
15
16
*/
16
- build ( steps ) {
17
+ build ( steps ) {
17
18
this . size = steps . length ;
18
19
19
20
return steps . map ( ( title , order ) => {
20
- var newStep = new StepNode ( title ) ;
21
+ let newStep = new StepNode ( title ) ;
21
22
22
23
newStep . order = order + 1 ;
23
24
24
- var prev = order === 0 ? null : newStep . order - 1 ;
25
- var next = order === this . size - 1 ? null : newStep . order + 1 ;
25
+ let prev = order === 0 ? null : newStep . order - 1 ;
26
+ let next = order === this . size - 1 ? null : newStep . order + 1 ;
26
27
27
28
newStep . nextStep = next ;
28
29
newStep . prevStep = prev ;
@@ -32,38 +33,44 @@ export class StepBuilder {
32
33
}
33
34
34
35
/**
35
- * Moves to the next step if there is any available, and returns the order number. If the current step is the last one, it returns the current step.
36
+ * Moves to the next step if there is any available, and returns
37
+ * the order number. If the current step is the last one, it returns
38
+ * the current step.
36
39
* @return {number } Order of the next available step
37
40
*/
38
- next ( ) {
41
+ next ( ) {
39
42
this . current = this . current === this . size ? this . current : this . current + 1 ;
40
43
return this . current ;
41
44
}
42
45
43
46
/**
44
- * Moves to the previous step if there is any available, and returns the order number. If the current step is the first one, it returns the current step.
47
+ * Moves to the previous step if there is any available, and returns
48
+ * the order number. If the current step is the first one, it returns
49
+ * the current step.
45
50
* @return {number } Order of the previous available step
46
51
*/
47
- prev ( ) {
52
+ prev ( ) {
48
53
this . current = this . current === 1 ? 1 : this . current - 1 ;
49
54
return this . current ;
50
55
}
51
56
52
57
/**
53
- * Jumps to the provided step and returns the order number. If the step is not available, returns the current step number.
58
+ * Jumps to the provided step and returns the order number. If the step
59
+ * is not available, returns the current step number.
54
60
* @param {number } step_order The order of the step to jump to.
55
61
* @return {number } Order of the jumped step
56
62
*/
57
- jump ( stepId ) {
63
+ jump ( stepId ) {
58
64
if ( stepId > 0 && stepId <= this . size ) {
59
65
this . current = stepId ;
60
66
}
61
67
return this . current ;
62
68
}
63
69
}
64
70
71
+ // prettier-ignore
65
72
class StepNode {
66
- constructor ( title ) {
73
+ constructor ( title ) {
67
74
this . order = null ;
68
75
this . title = title ;
69
76
this . nextStep = null ;
@@ -74,31 +81,31 @@ class StepNode {
74
81
* Checks if the step is the first one in the steps list
75
82
* @return {boolean }
76
83
*/
77
- isFirst ( ) {
78
- return ! Boolean ( this . prevStep ) ;
84
+ isFirst ( ) {
85
+ return ! this . prevStep ;
79
86
}
80
87
81
88
/**
82
89
* Checks if the step is the last one in the steps list
83
90
* @return {boolean }
84
91
*/
85
- isLast ( ) {
86
- return ! Boolean ( this . nextStep ) ;
92
+ isLast ( ) {
93
+ return ! this . nextStep ;
87
94
}
88
95
89
96
/**
90
97
* Checks if the current step has a previous step
91
98
* @return {boolean }
92
99
*/
93
- hasPrev ( ) {
100
+ hasPrev ( ) {
94
101
return Boolean ( this . prevStep ) ;
95
102
}
96
103
97
104
/**
98
105
* Checks if the current step has a next step
99
106
* @return {boolean }
100
107
*/
101
- hasNext ( ) {
108
+ hasNext ( ) {
102
109
return Boolean ( this . nextStep ) ;
103
110
}
104
111
}
0 commit comments