refactor(runtime-core): extract type SetRootFn (#3209)
This commit is contained in:
parent
e85e0a7f3a
commit
40794c80ca
@ -38,6 +38,8 @@ export function markAttrsAccessed() {
|
|||||||
accessedAttrs = true
|
accessedAttrs = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SetRootFn = ((root: VNode) => void) | undefined
|
||||||
|
|
||||||
export function renderComponentRoot(
|
export function renderComponentRoot(
|
||||||
instance: ComponentInternalInstance
|
instance: ComponentInternalInstance
|
||||||
): VNode {
|
): VNode {
|
||||||
@ -121,7 +123,7 @@ export function renderComponentRoot(
|
|||||||
// in dev mode, comments are preserved, and it's possible for a template
|
// 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
|
// to have comments along side the root element which makes it a fragment
|
||||||
let root = result
|
let root = result
|
||||||
let setRoot: ((root: VNode) => void) | undefined = undefined
|
let setRoot: SetRootFn = undefined
|
||||||
if (
|
if (
|
||||||
__DEV__ &&
|
__DEV__ &&
|
||||||
result.patchFlag > 0 &&
|
result.patchFlag > 0 &&
|
||||||
@ -246,9 +248,7 @@ export function renderComponentRoot(
|
|||||||
* template into a fragment root, but we need to locate the single element
|
* template into a fragment root, but we need to locate the single element
|
||||||
* root for attrs and scope id processing.
|
* root for attrs and scope id processing.
|
||||||
*/
|
*/
|
||||||
const getChildRoot = (
|
const getChildRoot = (vnode: VNode): [VNode, SetRootFn] => {
|
||||||
vnode: VNode
|
|
||||||
): [VNode, ((root: VNode) => void) | undefined] => {
|
|
||||||
const rawChildren = vnode.children as VNodeArrayChildren
|
const rawChildren = vnode.children as VNodeArrayChildren
|
||||||
const dynamicChildren = vnode.dynamicChildren
|
const dynamicChildren = vnode.dynamicChildren
|
||||||
const childRoot = filterSingleRoot(rawChildren)
|
const childRoot = filterSingleRoot(rawChildren)
|
||||||
@ -257,7 +257,7 @@ const getChildRoot = (
|
|||||||
}
|
}
|
||||||
const index = rawChildren.indexOf(childRoot)
|
const index = rawChildren.indexOf(childRoot)
|
||||||
const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1
|
const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1
|
||||||
const setRoot = (updatedRoot: VNode) => {
|
const setRoot: SetRootFn = (updatedRoot: VNode) => {
|
||||||
rawChildren[index] = updatedRoot
|
rawChildren[index] = updatedRoot
|
||||||
if (dynamicChildren) {
|
if (dynamicChildren) {
|
||||||
if (dynamicIndex > -1) {
|
if (dynamicIndex > -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user