From: edison Date: Fri, 13 May 2022 08:48:20 +0000 (+0800) Subject: refactor(runtime-core): extract type SetRootFn (#3209) X-Git-Tag: v3.2.34-beta.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40794c80ca944d9ba7dcdcb83f08d3e8e3057a3e;p=thirdparty%2Fvuejs%2Fcore.git refactor(runtime-core): extract type SetRootFn (#3209) --- diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index 8e338c31d6..d9de968a07 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -38,6 +38,8 @@ export function markAttrsAccessed() { accessedAttrs = true } +type SetRootFn = ((root: VNode) => void) | undefined + export function renderComponentRoot( instance: ComponentInternalInstance ): VNode { @@ -121,7 +123,7 @@ export function renderComponentRoot( // in dev mode, comments are preserved, and it's possible for a template // to have comments along side the root element which makes it a fragment let root = result - let setRoot: ((root: VNode) => void) | undefined = undefined + let setRoot: SetRootFn = undefined if ( __DEV__ && result.patchFlag > 0 && @@ -246,9 +248,7 @@ export function renderComponentRoot( * template into a fragment root, but we need to locate the single element * root for attrs and scope id processing. */ -const getChildRoot = ( - vnode: VNode -): [VNode, ((root: VNode) => void) | undefined] => { +const getChildRoot = (vnode: VNode): [VNode, SetRootFn] => { const rawChildren = vnode.children as VNodeArrayChildren const dynamicChildren = vnode.dynamicChildren const childRoot = filterSingleRoot(rawChildren) @@ -257,7 +257,7 @@ const getChildRoot = ( } const index = rawChildren.indexOf(childRoot) const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1 - const setRoot = (updatedRoot: VNode) => { + const setRoot: SetRootFn = (updatedRoot: VNode) => { rawChildren[index] = updatedRoot if (dynamicChildren) { if (dynamicIndex > -1) {