refactor(runtime-core): remove need for internal instance sink

This commit is contained in:
Evan You
2020-04-16 10:09:13 -04:00
parent 4d014dc3d3
commit 24e5ab33f5
5 changed files with 39 additions and 38 deletions

View File

@@ -18,7 +18,6 @@ import {
invokeArrayFns
} from '@vue/shared'
import { watch } from '../apiWatch'
import { SuspenseBoundary } from './Suspense'
import {
RendererInternals,
queuePostRenderEffect,
@@ -27,6 +26,7 @@ import {
RendererNode
} from '../renderer'
import { setTransitionHooks } from './BaseTransition'
import { ComponentPublicProxyTarget } from '../componentProxy'
type MatchPattern = string | RegExp | string[] | RegExp[]
@@ -40,9 +40,8 @@ type CacheKey = string | number | Component
type Cache = Map<CacheKey, VNode>
type Keys = Set<CacheKey>
export interface KeepAliveSink {
export interface KeepAliveContext extends ComponentPublicProxyTarget {
renderer: RendererInternals
parentSuspense: SuspenseBoundary | null
activate: (
vnode: VNode,
container: RendererElement,
@@ -76,25 +75,25 @@ const KeepAliveImpl = {
let current: VNode | null = null
const instance = getCurrentInstance()!
const parentSuspense = instance.suspense
// KeepAlive communicates with the instantiated renderer via the "sink"
// where the renderer passes in platform-specific functions, and the
// KeepAlive instance exposes activate/deactivate implementations.
// KeepAlive communicates with the instantiated renderer via the proxyTarget
// as a shared context where the renderer passes in its internals,
// and the KeepAlive instance exposes activate/deactivate implementations.
// The whole point of this is to avoid importing KeepAlive directly in the
// renderer to facilitate tree-shaking.
const sink = instance.sink as KeepAliveSink
const sharedContext = instance.proxyTarget as KeepAliveContext
const {
renderer: {
p: patch,
m: move,
um: _unmount,
o: { createElement }
},
parentSuspense
} = sink
}
} = sharedContext
const storageContainer = createElement('div')
sink.activate = (vnode, container, anchor, isSVG, optimized) => {
sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
const child = vnode.component!
move(vnode, container, anchor, MoveType.ENTER, parentSuspense)
// in case props have changed
@@ -116,7 +115,7 @@ const KeepAliveImpl = {
}, parentSuspense)
}
sink.deactivate = (vnode: VNode) => {
sharedContext.deactivate = (vnode: VNode) => {
move(vnode, storageContainer, null, MoveType.LEAVE, parentSuspense)
queuePostRenderEffect(() => {
const component = vnode.component!