MCPcopy
hub / github.com/preactjs/preact / constructNewChildrenArray

Function constructNewChildrenArray

src/diff/children.js:155–338  ·  view source on GitHub ↗

* @param {VNode} newParentVNode * @param {ComponentChildren[]} renderResult * @param {VNode[]} oldChildren

(
	newParentVNode,
	renderResult,
	oldChildren,
	oldDom,
	newChildrenLength
)

Source from the content-addressed store, hash-verified

153 * @param {VNode[]} oldChildren
154 */
155function constructNewChildrenArray(
156 newParentVNode,
157 renderResult,
158 oldChildren,
159 oldDom,
160 newChildrenLength
161) {
162 /** @type {number} */
163 let i;
164 /** @type {VNode} */
165 let childVNode;
166 /** @type {VNode} */
167 let oldVNode;
168
169 let oldChildrenLength = oldChildren.length,
170 remainingOldChildren = oldChildrenLength;
171
172 let skew = 0;
173
174 newParentVNode._children = new Array(newChildrenLength);
175 for (i = 0; i < newChildrenLength; i++) {
176 // @ts-expect-error We are reusing the childVNode variable to hold both the
177 // pre and post normalized childVNode
178 childVNode = renderResult[i];
179
180 if (
181 childVNode == NULL ||
182 typeof childVNode == 'boolean' ||
183 typeof childVNode == 'function'
184 ) {
185 newParentVNode._children[i] = NULL;
186 continue;
187 }
188 // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
189 // or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
190 // it's own DOM & etc. pointers
191 else if (
192 typeof childVNode == 'string' ||
193 typeof childVNode == 'number' ||
194 // eslint-disable-next-line valid-typeof
195 typeof childVNode == 'bigint' ||
196 childVNode.constructor == String
197 ) {
198 childVNode = newParentVNode._children[i] = createVNode(
199 NULL,
200 childVNode,
201 NULL,
202 NULL,
203 NULL
204 );
205 } else if (isArray(childVNode)) {
206 childVNode = newParentVNode._children[i] = createVNode(
207 Fragment,
208 { children: childVNode },
209 NULL,
210 NULL,
211 NULL
212 );

Callers 1

diffChildrenFunction · 0.85

Calls 4

createVNodeFunction · 0.90
getDomSiblingFunction · 0.90
unmountFunction · 0.90
findMatchingIndexFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…