Skip to content

Commit

Permalink
Introduce an internal version of replaceChildren (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
skirtles-code authored Nov 25, 2022
1 parent 1edc37b commit a5e31fb
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit a5e31fb

Please sign in to comment.