import { VNode } from './vnode' import { queuePostFlushCb } from './scheduler' export const SuspenseSymbol = __DEV__ ? Symbol('Suspense key') : Symbol() export interface SuspenseBoundary { parent: SuspenseBoundary | null contentTree: VNode | null fallbackTree: VNode | null deps: number isResolved: boolean bufferedJobs: Function[] container: HostElement resolve(): void } export function createSuspenseBoundary( parent: SuspenseBoundary | null, container: HostElement ): SuspenseBoundary { const suspense: SuspenseBoundary = { parent, container, deps: 0, contentTree: null, fallbackTree: null, isResolved: false, bufferedJobs: [], resolve() { suspense.isResolved = true let parent = suspense.parent let hasUnresolvedAncestor = false while (parent) { if (!parent.isResolved) { parent.bufferedJobs.push(...suspense.bufferedJobs) hasUnresolvedAncestor = true break } } if (!hasUnresolvedAncestor) { queuePostFlushCb(suspense.bufferedJobs) } suspense.isResolved = true } } return suspense }