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

Function recursive

src/index.js:103–303  ·  view source on GitHub ↗
(currentElement, currentContext)

Source from the content-addressed store, hash-verified

101 }
102
103 const recursive = (currentElement, currentContext) => {
104 if (Array.isArray(currentElement)) {
105 return Promise.all(
106 currentElement.map(item => recursive(item, currentContext)),
107 )
108 }
109
110 if (!currentElement) {
111 return Promise.resolve()
112 }
113
114 if (
115 typeof currentElement === 'string' ||
116 typeof currentElement === 'number'
117 ) {
118 // Just visit these, they are leaves so we don't keep traversing.
119 safeVisitor(currentElement, null, currentContext)
120 return Promise.resolve()
121 }
122
123 if (currentElement.type) {
124 if (currentElement.type._context) {
125 // eslint-disable-next-line no-param-reassign
126 currentElement.type._context._currentValue =
127 currentElement.props.value
128 }
129 if (currentElement.type.Provider && currentElement.type.Consumer) {
130 const el = currentElement.props.children(
131 currentElement.type.Provider._context._currentValue,
132 )
133 return recursive(el, currentContext)
134 }
135 }
136
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)) {

Callers 2

visitCurrentElementFunction · 0.85
reactTreeWalkerFunction · 0.85

Calls 15

safeVisitorFunction · 0.85
isReactElementFunction · 0.85
getTypeFunction · 0.85
isForwardRefFunction · 0.85
getPropsFunction · 0.85
getChildrenFunction · 0.85
visitCurrentElementFunction · 0.85
isClassComponentFunction · 0.85
providesChildContextFunction · 0.85
componentWillMountMethod · 0.80

Tested by

no test coverage detected