@@ -104,9 +104,16 @@ export class DefinitionWalker {
104104 return this . getParentSequence ( definition , stepId ) . step ;
105105 }
106106
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 ) ;
110117 }
111118
112119 private find (
@@ -138,7 +145,6 @@ export class DefinitionWalker {
138145 }
139146 }
140147 break ;
141-
142148 case StepChildrenType . branches :
143149 {
144150 const branches = children . items as Branches ;
@@ -153,51 +159,52 @@ export class DefinitionWalker {
153159 }
154160 }
155161 break ;
156-
157162 default :
158- throw new Error ( `Step children type ${ children . type } is not supported ` ) ;
163+ throw new Error ( `Not supported step children type: ${ children . type } ` ) ;
159164 }
160165 }
161166 }
162167 return false ;
163168 }
164169
165- private iterate ( sequence : Sequence , callback : StepForEachCallback ) : boolean {
170+ private iterateSequence ( sequence : Sequence , callback : StepForEachCallback ) : boolean {
166171 const count = sequence . length ;
167172 for ( let index = 0 ; index < count ; index ++ ) {
168173 const step = sequence [ index ] ;
169174 if ( callback ( step , index , sequence ) === false ) {
170175 return false ;
171176 }
177+ if ( ! this . iterateStep ( step , callback ) ) {
178+ return false ;
179+ }
180+ }
181+ return true ;
182+ }
172183
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 ;
182193 }
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 ;
194202 }
195203 }
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 } ` ) ;
201208 }
202209 }
203210 return true ;
0 commit comments