export type ComponentType = ComponentClass | FunctionalComponent
-// this interface is merged with the class type
-// to represent a mounted component
export interface ComponentInstance<P = {}, D = {}> extends InternalComponent {
$vnode: MountedVNode
$data: D
$slots: Slots
$root: ComponentInstance
$children: ComponentInstance[]
- $options: ComponentOptions<P, D>
+ $options: ComponentOptions<this>
data?(): Partial<D>
render(props: Readonly<P>, slots: Slots, attrs: Data): any
-import { EMPTY_OBJ } from './utils'
+import { EMPTY_OBJ, NOOP } from './utils'
import { computed, stop, ComputedGetter } from '@vue/observer'
import { ComponentClass, ComponentInstance } from './component'
import { ComponentComputedOptions } from './componentOptions'
> = (instance._computedGetters = {})
const proxy = instance.$proxy
for (const key in computedOptions) {
- handles[key] = computed(computedOptions[key], proxy)
+ const option = computedOptions[key]
+ const getter = typeof option === 'function' ? option : option.get || NOOP
+ handles[key] = computed(getter, proxy)
}
instance.$computed = new Proxy(
{},
-import { MergedComponent, ComponentInstance } from './component'
+import { ComponentInstance } from './component'
import { Slots } from './vdom'
export type Data = Record<string, any>
-export interface ComponentOptions<
- P = {},
- D = {},
- M = {},
- C = {},
- This = MergedComponent<P, D> & M & C
-> {
- data?: (this: This) => Partial<D>
- props?: ComponentPropsOptions<P>
+export interface ComponentOptions<This = ComponentInstance> {
+ data?(): object
+ props?: ComponentPropsOptions
computed?: ComponentComputedOptions<This>
watch?: ComponentWatchOptions<This>
- render?: (this: This, props: Readonly<P>, slots: Slots, attrs: Data) => any
+ render?: (this: This, props: Readonly<Data>, slots: Slots, attrs: Data) => any
inheritAttrs?: boolean
displayName?: string
// TODO other options
}
export interface ComponentComputedOptions<This = ComponentInstance> {
- [key: string]: (this: This, c: any) => any
+ [key: string]: ((this: This, c: This) => any) | SingleComputedOptions<This>
+}
+
+type SingleComputedOptions<This> = {
+ get: (this: This, c: This) => any
+ set?: (value: any) => void
+ cache?: boolean
}
export interface ComponentWatchOptions<This = ComponentInstance> {
const root = document.createElement('div')
document.body.appendChild(root)
- const instance = new Vue<any>({
+ const instance = new Vue({
data() {
return { count: 0 }
},
render,
nextTick,
Component,
- ComponentOptions,
createComponentInstance
} from '@vue/renderer-dom'
-import { MergedComponent } from '../../core/src/component'
-class Vue<
- P extends object = {},
- D extends object = {},
- M extends object = {},
- C extends object = {}
-> extends Component {
+// Note: typing for this is intentionally loose, as it will be using 2.x types.
+class Vue extends Component {
static h = h
static render = render
static nextTick = nextTick
- constructor(options: ComponentOptions<P, D, M, C> & { el?: any }) {
+ constructor(options: any) {
super()
if (!options) {
return
}
}
-interface Vue<P, D, M, C> {
- $mount(el: any): MergedComponent<P, D> & M & C
+interface Vue {
+ $mount(el: any): any
}
export default Vue