Skip to content

Introduce an internal version of replaceChildren #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/vue-vnode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const addProps = (
checkArguments('addProps', [children, callback, options], ['array', 'function', 'object'])
}

return replaceChildren(children, (vnode) => {
return replaceChildrenInternal(children, (vnode) => {
const props = callback(vnode)

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

return replaceChildrenInternal(children, callback, options)
}

const replaceChildrenInternal = (
children: VNodeArrayChildren,
callback: (vnode: VNode) => (VNode | VNodeArrayChildren | string | number | void),
options: IterationOptions
): VNodeArrayChildren => {
let nc: VNodeArrayChildren | null = null

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

if (isFragment(child)) {
const oldFragmentChildren = getFragmentChildren(child)
const newFragmentChildren = replaceChildren(oldFragmentChildren, callback, options)
const newFragmentChildren = replaceChildrenInternal(oldFragmentChildren, callback, options)

let newChild: VNodeChild = child

Expand Down Expand Up @@ -313,7 +321,7 @@ export const betweenChildren = (

let previousVNode: VNode | null = null

return replaceChildren(children, vnode => {
return replaceChildrenInternal(children, vnode => {
let insertedNodes: VNode | VNodeArrayChildren | string | number | void = undefined

if (previousVNode) {
Expand Down