Skip to content

Commit

Permalink
refactor(runtime-core): move updateCompnent into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 10, 2020
1 parent 2fb0add commit cda50ea
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,38 +968,7 @@ function baseCreateRenderer(
)
}
} else {
const instance = (n2.component = n1.component)!

if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
if (
__FEATURE_SUSPENSE__ &&
instance.asyncDep &&
!instance.asyncResolved
) {
// async & still pending - just update props and slots
// since the component's reactive effect for render isn't set-up yet
if (__DEV__) {
pushWarningContext(n2)
}
updateComponentPreRender(instance, n2, optimized)
if (__DEV__) {
popWarningContext()
}
return
} else {
// normal update
instance.next = n2
// in case the child component is also queued, remove it to avoid
// double updating the same child component in the same flush.
invalidateJob(instance.update)
// instance.update is the reactive effect runner.
instance.update()
}
} else {
// no update needed. just copy over properties
n2.component = n1.component
n2.el = n1.el
}
updateComponent(n1, n2, parentComponent, optimized)
}
}

Expand Down Expand Up @@ -1077,6 +1046,45 @@ function baseCreateRenderer(
}
}

const updateComponent = (
n1: VNode,
n2: VNode,
parentComponent: ComponentInternalInstance | null,
optimized: boolean
) => {
const instance = (n2.component = n1.component)!
if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
if (
__FEATURE_SUSPENSE__ &&
instance.asyncDep &&
!instance.asyncResolved
) {
// async & still pending - just update props and slots
// since the component's reactive effect for render isn't set-up yet
if (__DEV__) {
pushWarningContext(n2)
}
updateComponentPreRender(instance, n2, optimized)
if (__DEV__) {
popWarningContext()
}
return
} else {
// normal update
instance.next = n2
// in case the child component is also queued, remove it to avoid
// double updating the same child component in the same flush.
invalidateJob(instance.update)
// instance.update is the reactive effect runner.
instance.update()
}
} else {
// no update needed. just copy over properties
n2.component = n1.component
n2.el = n1.el
}
}

const setupRenderEffect: SetupRenderEffectFn = (
instance,
initialVNode,
Expand Down

0 comments on commit cda50ea

Please sign in to comment.