@@ -66,13 +66,8 @@ export default function reactTreeWalker(
6666 options = defaultOptions ,
6767) {
6868 return new Promise ( resolve => {
69- const doVisit = ( getChildren , visitorResult , childContext ) => {
70- const doTraverse = shouldContinue => {
71- if ( ! shouldContinue ) {
72- // We recieved a false, which indicates a desire to stop traversal.
73- resolve ( )
74- }
75-
69+ const doVisit = ( getChildren , visitResult , childContext ) => {
70+ const visitChildren = ( ) => {
7671 const child = ensureChild ( getChildren ( ) )
7772 const theChildContext =
7873 typeof childContext === 'function' ? childContext ( ) : childContext
@@ -97,25 +92,34 @@ export default function reactTreeWalker(
9792 }
9893 }
9994
100- if ( visitorResult === false ) {
95+ if ( visitResult === false ) {
10196 // Visitor returned false, indicating a desire to not traverse.
10297 resolve ( )
103- } else if ( isPromise ( visitorResult ) ) {
98+ } else if ( isPromise ( visitResult ) ) {
10499 // We need to execute the result and pass it's result through to our
105100 // continuer.
106- visitorResult . then ( doTraverse ) . catch ( e => {
107- console . log (
108- 'Error occurred in Promise based visitor result provided to react-tree-walker.' ,
109- )
110- if ( e ) {
111- console . log ( e )
112- if ( e . stack ) {
113- console . log ( e . stack )
101+ visitResult
102+ . then ( promiseResult => {
103+ if ( promiseResult === false ) {
104+ resolve ( )
105+ } else {
106+ visitChildren ( )
114107 }
115- }
116- } )
108+ } )
109+ . catch ( e => {
110+ console . log (
111+ 'Error occurred in Promise based visitor provided to react-tree-walker.' ,
112+ )
113+ if ( e ) {
114+ console . log ( e )
115+ if ( e . stack ) {
116+ console . log ( e . stack )
117+ }
118+ }
119+ } )
117120 } else {
118- doTraverse ( true )
121+ // Visitor returned true, indicating a desire to continue traversing.
122+ visitChildren ( )
119123 }
120124 }
121125
0 commit comments