vue3-yuanma/packages/runtime-core/src/suspense.ts

57 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-09-09 17:59:53 +00:00
import { VNode } from './vnode'
2019-09-07 15:28:40 +00:00
export const SuspenseSymbol = __DEV__ ? Symbol('Suspense key') : Symbol()
2019-09-09 20:00:50 +00:00
export interface SuspenseBoundary<
HostNode,
HostElement,
HostVNode = VNode<HostNode, HostElement>
> {
vnode: HostVNode
2019-09-09 17:59:53 +00:00
parent: SuspenseBoundary<HostNode, HostElement> | null
2019-09-09 20:00:50 +00:00
contentTree: HostVNode | null
oldContentTree: HostVNode | null
fallbackTree: HostVNode | null
oldFallbackTree: HostVNode | null
2019-09-07 15:28:40 +00:00
deps: number
isResolved: boolean
2019-09-09 17:59:53 +00:00
bufferedJobs: Function[]
2019-09-09 20:00:50 +00:00
onRetry(fn: Function): void
retry(): void
onResolve(fn: Function): void
2019-09-07 15:28:40 +00:00
resolve(): void
}
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>,
parent: SuspenseBoundary<HostNode, HostElement> | null
2019-09-09 17:59:53 +00:00
): SuspenseBoundary<HostNode, HostElement> {
2019-09-09 20:00:50 +00:00
let retry: Function
let resolve: Function
2019-09-09 17:59:53 +00:00
const suspense: SuspenseBoundary<HostNode, HostElement> = {
2019-09-09 20:00:50 +00:00
vnode,
2019-09-09 17:59:53 +00:00
parent,
2019-09-07 15:28:40 +00:00
deps: 0,
2019-09-09 17:59:53 +00:00
contentTree: null,
2019-09-09 20:00:50 +00:00
oldContentTree: null,
2019-09-09 17:59:53 +00:00
fallbackTree: null,
2019-09-09 20:00:50 +00:00
oldFallbackTree: null,
2019-09-07 15:28:40 +00:00
isResolved: false,
2019-09-09 17:59:53 +00:00
bufferedJobs: [],
2019-09-09 20:00:50 +00:00
onRetry(fn: Function) {
retry = fn
},
retry() {
retry()
},
onResolve(fn: Function) {
resolve = fn
},
2019-09-07 15:28:40 +00:00
resolve() {
2019-09-09 20:00:50 +00:00
resolve()
2019-09-07 15:28:40 +00:00
}
}
2019-09-09 17:59:53 +00:00
return suspense
2019-09-07 15:28:40 +00:00
}