@@ -104,9 +104,16 @@ export class DefinitionWalker {
104
104
return this . getParentSequence ( definition , stepId ) . step ;
105
105
}
106
106
107
- public forEach ( sequenceOrDefinition : Sequence | Definition , callback : StepForEachCallback ) {
108
- const sequence = Array . isArray ( sequenceOrDefinition ) ? sequenceOrDefinition : sequenceOrDefinition . sequence ;
109
- this . iterate ( sequence , callback ) ;
107
+ public forEach ( definition : Definition , callback : StepForEachCallback ) {
108
+ this . iterateSequence ( definition . sequence , callback ) ;
109
+ }
110
+
111
+ public forEachSequence ( sequence : Sequence , callback : StepForEachCallback ) {
112
+ this . iterateSequence ( sequence , callback ) ;
113
+ }
114
+
115
+ public forEachChildren ( step : Step , callback : StepForEachCallback ) {
116
+ this . iterateStep ( step , callback ) ;
110
117
}
111
118
112
119
private find (
@@ -138,7 +145,6 @@ export class DefinitionWalker {
138
145
}
139
146
}
140
147
break ;
141
-
142
148
case StepChildrenType . branches :
143
149
{
144
150
const branches = children . items as Branches ;
@@ -153,51 +159,52 @@ export class DefinitionWalker {
153
159
}
154
160
}
155
161
break ;
156
-
157
162
default :
158
- throw new Error ( `Step children type ${ children . type } is not supported ` ) ;
163
+ throw new Error ( `Not supported step children type: ${ children . type } ` ) ;
159
164
}
160
165
}
161
166
}
162
167
return false ;
163
168
}
164
169
165
- private iterate ( sequence : Sequence , callback : StepForEachCallback ) : boolean {
170
+ private iterateSequence ( sequence : Sequence , callback : StepForEachCallback ) : boolean {
166
171
const count = sequence . length ;
167
172
for ( let index = 0 ; index < count ; index ++ ) {
168
173
const step = sequence [ index ] ;
169
174
if ( callback ( step , index , sequence ) === false ) {
170
175
return false ;
171
176
}
177
+ if ( ! this . iterateStep ( step , callback ) ) {
178
+ return false ;
179
+ }
180
+ }
181
+ return true ;
182
+ }
172
183
173
- const children = this . getChildren ( step ) ;
174
- if ( children ) {
175
- switch ( children . type ) {
176
- case StepChildrenType . sequence :
177
- {
178
- const childSequence = children . items as Sequence ;
179
- if ( this . iterate ( childSequence , callback ) === false ) {
180
- return false ;
181
- }
184
+ private iterateStep ( step : Step , callback : StepForEachCallback ) : boolean {
185
+ const children = this . getChildren ( step ) ;
186
+ if ( children ) {
187
+ switch ( children . type ) {
188
+ case StepChildrenType . sequence :
189
+ {
190
+ const sequence = children . items as Sequence ;
191
+ if ( ! this . iterateSequence ( sequence , callback ) ) {
192
+ return false ;
182
193
}
183
- break ;
184
-
185
- case StepChildrenType . branches :
186
- {
187
- const branches = children . items as Branches ;
188
- const branchNames = Object . keys ( branches ) ;
189
- for ( const branchName of branchNames ) {
190
- const parentSequence = branches [ branchName ] ;
191
- if ( this . iterate ( parentSequence , callback ) === false ) {
192
- return false ;
193
- }
194
+ }
195
+ break ;
196
+ case StepChildrenType . branches :
197
+ {
198
+ const sequences = Object . values ( children . items as Branches ) ;
199
+ for ( const sequence of sequences ) {
200
+ if ( ! this . iterateSequence ( sequence , callback ) ) {
201
+ return false ;
194
202
}
195
203
}
196
- break ;
197
-
198
- default :
199
- throw new Error ( `Step children type ${ children . type } is not supported` ) ;
200
- }
204
+ }
205
+ break ;
206
+ default :
207
+ throw new Error ( `Not supported step children type: ${ children . type } ` ) ;
201
208
}
202
209
}
203
210
return true ;
0 commit comments