feat(core): keep-alive

This commit is contained in:
Evan You
2019-10-29 22:28:38 -04:00
parent 083296ead6
commit c6cbca25fe
11 changed files with 351 additions and 53 deletions

View File

@@ -42,6 +42,7 @@ export interface FunctionalComponent<P = {}> {
}
export type Component = ComponentOptions | FunctionalComponent
export { ComponentOptions }
type LifecycleHook = Function[] | null
@@ -89,13 +90,10 @@ export interface ComponentInternalInstance {
// after initialized (e.g. inline handlers)
renderCache: (Function | VNode)[] | null
// assets for fast resolution
components: Record<string, Component>
directives: Record<string, Directive>
asyncDep: Promise<any> | null
asyncResult: unknown
asyncResolved: boolean
// the rest are only for stateful components
renderContext: Data
data: Data
@@ -108,11 +106,17 @@ export interface ComponentInternalInstance {
refs: Data
emit: Emit
// user namespace
user: { [key: string]: any }
// suspense related
asyncDep: Promise<any> | null
asyncResult: unknown
asyncResolved: boolean
// storage for any extra properties
sink: { [key: string]: any }
// lifecycle
isUnmounted: boolean
isDeactivated: boolean
[LifecycleHooks.BEFORE_CREATE]: LifecycleHook
[LifecycleHooks.CREATED]: LifecycleHook
[LifecycleHooks.BEFORE_MOUNT]: LifecycleHook
@@ -173,11 +177,13 @@ export function createComponentInstance(
asyncResolved: false,
// user namespace for storing whatever the user assigns to `this`
user: {},
// can also be used as a wildcard storage for ad-hoc injections internally
sink: {},
// lifecycle hooks
// not using enums here because it results in computed properties
isUnmounted: false,
isDeactivated: false,
bc: null,
c: null,
bm: null,