MCPcopy Create free account
hub / github.com/ctrlplusb/react-tree-walker / visitCurrentElement

Function visitCurrentElement

src/index.js:139–182  ·  view source on GitHub ↗
(
            render,
            compInstance,
            elContext,
            childContext,
          )

Source from the content-addressed store, hash-verified

137 if (isReactElement(currentElement)) {
138 return new Promise(innerResolve => {
139 const visitCurrentElement = (
140 render,
141 compInstance,
142 elContext,
143 childContext,
144 ) =>
145 Promise.resolve(
146 safeVisitor(
147 currentElement,
148 compInstance,
149 elContext,
150 childContext,
151 ),
152 )
153 .then(result => {
154 if (result !== false) {
155 // A false wasn't returned so we will attempt to visit the children
156 // for the current element.
157 const tempChildren = render()
158 const children = ensureChild(tempChildren)
159 if (children) {
160 if (Array.isArray(children)) {
161 // If its a react Children collection we need to breadth-first
162 // traverse each of them, and pMapSeries allows us to do a
163 // depth-first traversal that respects Promises. Thanks @sindresorhus!
164 return pMapSeries(
165 children,
166 child =>
167 child
168 ? recursive(child, childContext)
169 : Promise.resolve(),
170 )
171 .then(innerResolve, reject)
172 .catch(reject)
173 }
174 // Otherwise we pass the individual child to the next recursion.
175 return recursive(children, childContext)
176 .then(innerResolve, reject)
177 .catch(reject)
178 }
179 }
180 return undefined
181 })
182 .catch(reject)
183
184 if (
185 typeof getType(currentElement) === 'function' ||

Callers 1

recursiveFunction · 0.85

Calls 4

safeVisitorFunction · 0.85
ensureChildFunction · 0.85
pMapSeriesFunction · 0.85
recursiveFunction · 0.85

Tested by

no test coverage detected