@@ -18,7 +18,7 @@ const pReduce = (iterable, reducer, initVal) =>
1818 const iterator = iterable [ Symbol . iterator ] ( )
1919 let i = 0
2020
21- const next = ( total ) => {
21+ const next = total => {
2222 const el = iterator . next ( )
2323
2424 if ( el . done ) {
@@ -27,7 +27,7 @@ const pReduce = (iterable, reducer, initVal) =>
2727 }
2828
2929 Promise . all ( [ total , el . value ] )
30- . then ( ( value ) => {
30+ . then ( value => {
3131 // eslint-disable-next-line no-plusplus
3232 next ( reducer ( value [ 0 ] , value [ 1 ] , i ++ ) )
3333 } )
@@ -43,7 +43,7 @@ const pMapSeries = (iterable, iterator) => {
4343 const ret = [ ]
4444
4545 return pReduce ( iterable , ( a , b , i ) =>
46- Promise . resolve ( iterator ( b , i ) ) . then ( ( val ) => {
46+ Promise . resolve ( iterator ( b , i ) ) . then ( val => {
4747 ret . push ( val )
4848 } ) ,
4949 ) . then ( ( ) => ret )
@@ -54,17 +54,23 @@ export const isPromise = x => x != null && typeof x.then === 'function'
5454// Recurse an React Element tree, running visitor on each element.
5555// If visitor returns `false`, don't call the element's render function
5656// or recurse into its child elements
57- export default function reactTreeWalker ( element , visitor , context , options = defaultOptions ) {
58- return new Promise ( ( resolve ) => {
57+ export default function reactTreeWalker (
58+ element ,
59+ visitor ,
60+ context ,
61+ options = defaultOptions ,
62+ ) {
63+ return new Promise ( resolve => {
5964 const doVisit = ( getChildren , visitorResult , childContext ) => {
60- const doTraverse = ( shouldContinue ) => {
65+ const doTraverse = shouldContinue => {
6166 if ( ! shouldContinue ) {
6267 // We recieved a false, which indicates a desire to stop traversal.
6368 resolve ( )
6469 }
6570
6671 const child = getChildren ( )
67- const theChildContext = typeof childContext === 'function' ? childContext ( ) : childContext
72+ const theChildContext =
73+ typeof childContext === 'function' ? childContext ( ) : childContext
6874
6975 if ( child == null ) {
7076 // If no children then we can't traverse. We've reached the leaf.
@@ -73,12 +79,16 @@ export default function reactTreeWalker(element, visitor, context, options = def
7379 // If its a react Children collection we need to breadth-first
7480 // traverse each of them.
7581 const mapper = aChild =>
76- aChild ? reactTreeWalker ( aChild , visitor , theChildContext , options ) : undefined
82+ aChild
83+ ? reactTreeWalker ( aChild , visitor , theChildContext , options )
84+ : undefined
7785 // pMapSeries allows us to do depth-first traversal. Thanks @sindresorhus!
7886 pMapSeries ( Children . map ( child , cur => cur ) , mapper ) . then ( resolve )
7987 } else {
8088 // Otherwise we pass the individual child to the next recursion.
81- reactTreeWalker ( child , visitor , theChildContext , options ) . then ( resolve )
89+ reactTreeWalker ( child , visitor , theChildContext , options ) . then (
90+ resolve ,
91+ )
8292 }
8393 }
8494
@@ -88,7 +98,7 @@ export default function reactTreeWalker(element, visitor, context, options = def
8898 } else if ( isPromise ( visitorResult ) ) {
8999 // We need to execute the result and pass it's result through to our
90100 // continuer.
91- visitorResult . then ( doTraverse ) . catch ( ( e ) => {
101+ visitorResult . then ( doTraverse ) . catch ( e => {
92102 console . log (
93103 'Error occurred in Promise based visitor result provided to react-tree-walker.' ,
94104 )
@@ -112,7 +122,8 @@ export default function reactTreeWalker(element, visitor, context, options = def
112122 // Is this a class component? (http://bit.ly/2j9Ifk3)
113123 const isReactClassComponent =
114124 Component . prototype &&
115- ( Component . prototype . isReactComponent || Component . prototype . isPureReactComponent )
125+ ( Component . prototype . isReactComponent ||
126+ Component . prototype . isPureReactComponent )
116127
117128 if ( isReactClassComponent ) {
118129 // React class component
@@ -124,7 +135,7 @@ export default function reactTreeWalker(element, visitor, context, options = def
124135 instance . context = instance . context || context
125136
126137 // Make the setState synchronous.
127- instance . setState = ( newState ) => {
138+ instance . setState = newState => {
128139 instance . state = Object . assign ( { } , instance . state , newState )
129140 }
130141
@@ -144,7 +155,9 @@ export default function reactTreeWalker(element, visitor, context, options = def
144155 // This is an experimental feature, we don't want to break
145156 // the bootstrapping process, but lets warn the user it
146157 // occurred.
147- console . warn ( 'Error calling componentWillUnmount whilst walking your react tree' )
158+ console . warn (
159+ 'Error calling componentWillUnmount whilst walking your react tree' ,
160+ )
148161 console . warn ( err )
149162 }
150163 }
@@ -161,17 +174,24 @@ export default function reactTreeWalker(element, visitor, context, options = def
161174 )
162175 } else {
163176 // Stateless Functional Component
164- doVisit ( ( ) => Component ( props , context ) , visitor ( element , null , context ) , context )
177+ doVisit (
178+ ( ) => Component ( props , context ) ,
179+ visitor ( element , null , context ) ,
180+ context ,
181+ )
165182 }
166183 } else {
167184 // This must be a basic element, such as a string or dom node.
168185 doVisit (
169- ( ) => ( element . props && element . props . children ? element . props . children : undefined ) ,
186+ ( ) =>
187+ element . props && element . props . children
188+ ? element . props . children
189+ : undefined ,
170190 visitor ( element , null , context ) ,
171191 context ,
172192 )
173193 }
174- } ) . catch ( ( err ) => {
194+ } ) . catch ( err => {
175195 // We don't want errors to be swallowed!
176196 console . error ( 'Error walking your react tree' )
177197 console . error ( err )
0 commit comments