refactor(suspense): move more suspense details into suspense.ts
This commit is contained in:
parent
17d71fa407
commit
4dd5d2cb74
@ -26,7 +26,6 @@ import {
|
|||||||
EMPTY_ARR,
|
EMPTY_ARR,
|
||||||
isReservedProp,
|
isReservedProp,
|
||||||
isFunction,
|
isFunction,
|
||||||
isArray,
|
|
||||||
PatchFlags
|
PatchFlags
|
||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import { queueJob, queuePostFlushCb, flushPostFlushCbs } from './scheduler'
|
import { queueJob, queuePostFlushCb, flushPostFlushCbs } from './scheduler'
|
||||||
@ -46,7 +45,11 @@ import { pushWarningContext, popWarningContext, warn } from './warning'
|
|||||||
import { invokeDirectiveHook } from './directives'
|
import { invokeDirectiveHook } from './directives'
|
||||||
import { ComponentPublicInstance } from './componentProxy'
|
import { ComponentPublicInstance } from './componentProxy'
|
||||||
import { App, createAppAPI } from './apiApp'
|
import { App, createAppAPI } from './apiApp'
|
||||||
import { SuspenseBoundary, SuspenseImpl } from './suspense'
|
import {
|
||||||
|
SuspenseBoundary,
|
||||||
|
SuspenseImpl,
|
||||||
|
queueEffectWithSuspense
|
||||||
|
} from './suspense'
|
||||||
import { ErrorCodes, callWithErrorHandling } from './errorHandling'
|
import { ErrorCodes, callWithErrorHandling } from './errorHandling'
|
||||||
|
|
||||||
export interface RendererOptions<HostNode = any, HostElement = any> {
|
export interface RendererOptions<HostNode = any, HostElement = any> {
|
||||||
@ -135,20 +138,7 @@ function invokeHooks(hooks: Function[], arg?: DebuggerEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const queuePostRenderEffect = __FEATURE_SUSPENSE__
|
export const queuePostRenderEffect = __FEATURE_SUSPENSE__
|
||||||
? (
|
? queueEffectWithSuspense
|
||||||
fn: Function | Function[],
|
|
||||||
suspense: SuspenseBoundary<any, any> | null
|
|
||||||
) => {
|
|
||||||
if (suspense !== null && !suspense.isResolved) {
|
|
||||||
if (isArray(fn)) {
|
|
||||||
suspense.effects.push(...fn)
|
|
||||||
} else {
|
|
||||||
suspense.effects.push(fn)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
queuePostFlushCb(fn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
: queuePostFlushCb
|
: queuePostFlushCb
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1354,13 +1344,7 @@ export function createRenderer<
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {
|
if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {
|
||||||
const suspense = vnode.suspense!
|
vnode.suspense!.move(container, anchor)
|
||||||
move(
|
|
||||||
suspense.isResolved ? suspense.subTree : suspense.fallbackTree,
|
|
||||||
container,
|
|
||||||
anchor
|
|
||||||
)
|
|
||||||
suspense.container = container
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (vnode.type === Fragment) {
|
if (vnode.type === Fragment) {
|
||||||
@ -1503,10 +1487,7 @@ export function createRenderer<
|
|||||||
return getNextHostNode(vnode.component!.subTree)
|
return getNextHostNode(vnode.component!.subTree)
|
||||||
}
|
}
|
||||||
if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {
|
if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {
|
||||||
const suspense = vnode.suspense!
|
return vnode.suspense!.next()
|
||||||
return getNextHostNode(
|
|
||||||
suspense.isResolved ? suspense.subTree : suspense.fallbackTree
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return hostNextSibling((vnode.anchor || vnode.el)!)
|
return hostNextSibling((vnode.anchor || vnode.el)!)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { VNode, normalizeVNode, VNodeChild, VNodeTypes } from './vnode'
|
import { VNode, normalizeVNode, VNodeChild, VNodeTypes } from './vnode'
|
||||||
import { ShapeFlags } from './shapeFlags'
|
import { ShapeFlags } from './shapeFlags'
|
||||||
import { isFunction } from '@vue/shared'
|
import { isFunction, isArray } from '@vue/shared'
|
||||||
import { ComponentInternalInstance, handleSetupResult } from './component'
|
import { ComponentInternalInstance, handleSetupResult } from './component'
|
||||||
import { Slots } from './componentSlots'
|
import { Slots } from './componentSlots'
|
||||||
import { RendererInternals } from './createRenderer'
|
import { RendererInternals } from './createRenderer'
|
||||||
@ -197,6 +197,8 @@ export interface SuspenseBoundary<
|
|||||||
effects: Function[]
|
effects: Function[]
|
||||||
resolve(): void
|
resolve(): void
|
||||||
restart(): void
|
restart(): void
|
||||||
|
move(container: HostElement, anchor: HostNode | null): void
|
||||||
|
next(): HostNode | null
|
||||||
registerDep(
|
registerDep(
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
setupRenderEffect: (
|
setupRenderEffect: (
|
||||||
@ -354,6 +356,21 @@ function createSuspenseBoundary<HostNode, HostElement>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
move(container, anchor) {
|
||||||
|
move(
|
||||||
|
suspense.isResolved ? suspense.subTree : suspense.fallbackTree,
|
||||||
|
container,
|
||||||
|
anchor
|
||||||
|
)
|
||||||
|
suspense.container = container
|
||||||
|
},
|
||||||
|
|
||||||
|
next() {
|
||||||
|
return next(
|
||||||
|
suspense.isResolved ? suspense.subTree : suspense.fallbackTree
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
registerDep(instance, setupRenderEffect) {
|
registerDep(instance, setupRenderEffect) {
|
||||||
// suspense is already resolved, need to recede.
|
// suspense is already resolved, need to recede.
|
||||||
// use queueJob so it's handled synchronously after patching the current
|
// use queueJob so it's handled synchronously after patching the current
|
||||||
@ -439,3 +456,18 @@ function normalizeSuspenseChildren(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function queueEffectWithSuspense(
|
||||||
|
fn: Function | Function[],
|
||||||
|
suspense: SuspenseBoundary | null
|
||||||
|
): void {
|
||||||
|
if (suspense !== null && !suspense.isResolved) {
|
||||||
|
if (isArray(fn)) {
|
||||||
|
suspense.effects.push(...fn)
|
||||||
|
} else {
|
||||||
|
suspense.effects.push(fn)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
queuePostFlushCb(fn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user