2019-10-08 16:43:13 +00:00
|
|
|
import { VNode, normalizeVNode, VNodeChild } from './vnode'
|
2019-09-10 15:01:11 +00:00
|
|
|
import { ShapeFlags } from '.'
|
2019-09-10 15:17:26 +00:00
|
|
|
import { isFunction } from '@vue/shared'
|
2019-09-11 21:38:26 +00:00
|
|
|
import { ComponentInternalInstance } from './component'
|
2019-10-08 16:43:13 +00:00
|
|
|
import { Slots } from './componentSlots'
|
2019-09-07 15:28:40 +00:00
|
|
|
|
2019-10-26 14:51:55 +00:00
|
|
|
export const SuspenseSymbol = Symbol(__DEV__ ? 'Suspense key' : undefined)
|
2019-09-07 15:28:40 +00:00
|
|
|
|
2019-09-09 20:00:50 +00:00
|
|
|
export interface SuspenseBoundary<
|
2019-09-11 14:09:00 +00:00
|
|
|
HostNode = any,
|
|
|
|
HostElement = any,
|
2019-09-09 20:00:50 +00:00
|
|
|
HostVNode = VNode<HostNode, HostElement>
|
|
|
|
> {
|
|
|
|
vnode: HostVNode
|
2019-09-09 17:59:53 +00:00
|
|
|
parent: SuspenseBoundary<HostNode, HostElement> | null
|
2019-09-11 21:38:26 +00:00
|
|
|
parentComponent: ComponentInternalInstance | null
|
2019-09-12 16:16:01 +00:00
|
|
|
isSVG: boolean
|
|
|
|
optimized: boolean
|
2019-09-10 15:01:11 +00:00
|
|
|
container: HostElement
|
2019-09-11 21:38:26 +00:00
|
|
|
hiddenContainer: HostElement
|
|
|
|
anchor: HostNode | null
|
2019-09-11 17:22:18 +00:00
|
|
|
subTree: HostVNode
|
|
|
|
fallbackTree: HostVNode
|
2019-09-07 15:28:40 +00:00
|
|
|
deps: number
|
|
|
|
isResolved: boolean
|
2019-09-11 17:22:18 +00:00
|
|
|
isUnmounted: boolean
|
2019-09-11 00:53:28 +00:00
|
|
|
effects: Function[]
|
2019-09-07 15:28:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:59:53 +00:00
|
|
|
export function createSuspenseBoundary<HostNode, HostElement>(
|
2019-09-09 20:00:50 +00:00
|
|
|
vnode: VNode<HostNode, HostElement>,
|
2019-09-10 14:09:04 +00:00
|
|
|
parent: SuspenseBoundary<HostNode, HostElement> | null,
|
2019-09-11 21:38:26 +00:00
|
|
|
parentComponent: ComponentInternalInstance | null,
|
2019-09-10 15:01:11 +00:00
|
|
|
container: HostElement,
|
2019-09-11 21:38:26 +00:00
|
|
|
hiddenContainer: HostElement,
|
2019-09-12 16:16:01 +00:00
|
|
|
anchor: HostNode | null,
|
|
|
|
isSVG: boolean,
|
|
|
|
optimized: boolean
|
2019-09-09 17:59:53 +00:00
|
|
|
): SuspenseBoundary<HostNode, HostElement> {
|
2019-09-10 14:09:04 +00:00
|
|
|
return {
|
2019-09-09 20:00:50 +00:00
|
|
|
vnode,
|
2019-09-09 17:59:53 +00:00
|
|
|
parent,
|
2019-09-11 21:38:26 +00:00
|
|
|
parentComponent,
|
2019-09-12 16:16:01 +00:00
|
|
|
isSVG,
|
|
|
|
optimized,
|
2019-09-10 15:01:11 +00:00
|
|
|
container,
|
2019-09-11 21:38:26 +00:00
|
|
|
hiddenContainer,
|
|
|
|
anchor,
|
2019-09-07 15:28:40 +00:00
|
|
|
deps: 0,
|
2019-09-11 17:22:18 +00:00
|
|
|
subTree: null as any, // will be set immediately after creation
|
|
|
|
fallbackTree: null as any, // will be set immediately after creation
|
2019-09-07 15:28:40 +00:00
|
|
|
isResolved: false,
|
2019-09-11 17:22:18 +00:00
|
|
|
isUnmounted: false,
|
2019-09-11 21:38:26 +00:00
|
|
|
effects: []
|
2019-09-07 15:28:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 15:01:11 +00:00
|
|
|
|
|
|
|
export function normalizeSuspenseChildren(
|
|
|
|
vnode: VNode
|
|
|
|
): {
|
|
|
|
content: VNode
|
|
|
|
fallback: VNode
|
|
|
|
} {
|
2019-09-10 15:17:26 +00:00
|
|
|
const { shapeFlag, children } = vnode
|
2019-09-10 15:01:11 +00:00
|
|
|
if (shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
|
2019-10-08 16:43:13 +00:00
|
|
|
const { default: d, fallback } = children as Slots
|
2019-09-10 15:01:11 +00:00
|
|
|
return {
|
2019-09-10 15:17:26 +00:00
|
|
|
content: normalizeVNode(isFunction(d) ? d() : d),
|
|
|
|
fallback: normalizeVNode(isFunction(fallback) ? fallback() : fallback)
|
2019-09-10 15:01:11 +00:00
|
|
|
}
|
2019-10-13 02:52:11 +00:00
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
content: normalizeVNode(children as VNodeChild),
|
|
|
|
fallback: normalizeVNode(null)
|
|
|
|
}
|
2019-09-10 15:01:11 +00:00
|
|
|
}
|
|
|
|
}
|