vue3-core/packages/core/src/componentOptions.ts

63 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Slots } from './vdom'
2018-09-19 23:35:38 +08:00
import { MountedComponent } from './component'
export type Data = Record<string, any>
export interface RenderFunction<P = Data> {
(props: P, slots: Slots, attrs: Data): any
2018-09-19 23:35:38 +08:00
}
export interface ComponentOptions<D = Data, P = Data> {
data?: () => Partial<D>
props?: ComponentPropsOptions<P>
computed?: ComponentComputedOptions<D, P>
watch?: ComponentWatchOptions<D, P>
render?: RenderFunction<P>
2018-09-24 11:28:21 +08:00
inheritAttrs?: boolean
2018-09-19 23:35:38 +08:00
// TODO other options
readonly [key: string]: any
}
export type ComponentPropsOptions<P = Data> = {
[K in keyof P]: PropValidator<P[K]>
}
export type Prop<T> = { (): T } | { new (...args: any[]): T & object }
export type PropType<T> = Prop<T> | Prop<T>[]
export type PropValidator<T> = PropOptions<T> | PropType<T>
export interface PropOptions<T = any> {
2018-10-03 06:29:14 +08:00
type?: PropType<T> | true | null
2018-09-19 23:35:38 +08:00
required?: boolean
default?: T | null | undefined | (() => T | null | undefined)
validator?(value: T): boolean
}
export interface ComponentComputedOptions<D = Data, P = Data> {
[key: string]: (this: MountedComponent<D, P> & D & P, c: any) => any
}
export interface ComponentWatchOptions<D = Data, P = Data> {
2018-09-24 11:16:14 +08:00
[key: string]: ComponentWatchOption<MountedComponent<D, P> & D & P>
}
export type ComponentWatchOption<C = any> =
| WatchHandler<C>
| WatchHandler<C>[]
| WatchOptionsWithHandler<C>
| string
export type WatchHandler<C = any> = (this: C, val: any, oldVal: any) => void
export interface WatchOptionsWithHandler<C = any> extends WatchOptions {
handler: WatchHandler<C>
}
export interface WatchOptions {
sync?: boolean
deep?: boolean
immediate?: boolean
2018-09-19 23:35:38 +08:00
}