import { EMPTY_OBJ, NOOP } from '@vue/shared' import { VNode, Slots, RenderNode, MountedVNode } from './vdom' import { Data, ComponentOptions, ComponentClassOptions, ComponentPropsOptions, WatchOptions } from './componentOptions' import { setupWatcher } from './componentWatch' import { Autorun, DebuggerEvent, ComputedGetter } from '@vue/observer' import { nextTick } from '@vue/scheduler' import { ErrorTypes } from './errorHandling' import { initializeComponentInstance } from './componentUtils' import { EventEmitter, invokeListeners } from './optional/eventEmitter' import { warn } from './warning' // public component instance type export interface Component
extends PublicInstanceMethods { readonly $el: any readonly $vnode: MountedVNode readonly $parentVNode: MountedVNode readonly $data: D readonly $props: Readonly
readonly $attrs: Readonly
readonly $slots: Slots
readonly $root: Component
readonly $parent: Component
readonly $children: Component[]
readonly $options: ComponentOptions
readonly $refs: Record {
data(): Partial , slots: Slots, attrs: Data, parentVNode: VNode): any
}
export interface LifecycleMethods {
beforeCreate(): void
created(): void
beforeMount(): void
mounted(): void
beforeUpdate(vnode: VNode): void
updated(vnode: VNode): void
beforeUnmount(): void
unmounted(): void
errorCaptured(): (
err: Error,
type: ErrorTypes,
instance: ComponentInstance | null,
vnode: VNode
) => boolean | void
activated(): void
deactivated(): void
renderTracked(e: DebuggerEvent): void
renderTriggered(e: DebuggerEvent): void
}
export interface ComponentClass extends ComponentClassOptions {
options?: ComponentOptions
new (): Component & D & P
}
export interface FunctionalComponent {
(props: P, slots: Slots, attrs: Data, parentVNode: VNode): any
props?: ComponentPropsOptions
displayName?: string
}
export type ComponentType = ComponentClass | FunctionalComponent
// Internal type that represents a mounted instance.
// It extends InternalComponent with mounted instance properties.
export interface ComponentInstance
extends InternalComponent,
Partial ['render']
$vnode: MountedVNode
$data: D
$props: P
$attrs: Data
$slots: Slots
$root: ComponentInstance
$children: ComponentInstance[]
$options: ComponentOptions
_updateHandle: Autorun
_queueJob: ((fn: () => void) => void)
_self: ComponentInstance // on proxies only
}
// actual implementation of the component
class InternalComponent implements PublicInstanceMethods {
get $el(): any {
const el = this.$vnode && this.$vnode.el
return typeof el === 'function' ? (el as any)() : el
}
$vnode: VNode | null = null
$parentVNode: VNode | null = null
$data: Data | null = null
$props: Data | null = null
$attrs: Data | null = null
$slots: Slots | null = null
$root: ComponentInstance | null = null
$parent: ComponentInstance | null = null
$children: ComponentInstance[] = []
$options: ComponentOptions | null = null
$refs: Record