Skip to content

Commit a5e31fb

Browse files
Introduce an internal version of replaceChildren (#4)
1 parent 1edc37b commit a5e31fb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: src/vue-vnode-utils.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export const addProps = (
220220
checkArguments('addProps', [children, callback, options], ['array', 'function', 'object'])
221221
}
222222

223-
return replaceChildren(children, (vnode) => {
223+
return replaceChildrenInternal(children, (vnode) => {
224224
const props = callback(vnode)
225225

226226
if (DEV) {
@@ -246,14 +246,22 @@ export const replaceChildren = (
246246
checkArguments('replaceChildren', [children, callback, options], ['array', 'function', 'object'])
247247
}
248248

249+
return replaceChildrenInternal(children, callback, options)
250+
}
251+
252+
const replaceChildrenInternal = (
253+
children: VNodeArrayChildren,
254+
callback: (vnode: VNode) => (VNode | VNodeArrayChildren | string | number | void),
255+
options: IterationOptions
256+
): VNodeArrayChildren => {
249257
let nc: VNodeArrayChildren | null = null
250258

251259
for (let index = 0; index < children.length; ++index) {
252260
const child = children[index]
253261

254262
if (isFragment(child)) {
255263
const oldFragmentChildren = getFragmentChildren(child)
256-
const newFragmentChildren = replaceChildren(oldFragmentChildren, callback, options)
264+
const newFragmentChildren = replaceChildrenInternal(oldFragmentChildren, callback, options)
257265

258266
let newChild: VNodeChild = child
259267

@@ -313,7 +321,7 @@ export const betweenChildren = (
313321

314322
let previousVNode: VNode | null = null
315323

316-
return replaceChildren(children, vnode => {
324+
return replaceChildrenInternal(children, vnode => {
317325
let insertedNodes: VNode | VNodeArrayChildren | string | number | void = undefined
318326

319327
if (previousVNode) {

0 commit comments

Comments
 (0)