import { EMPTY_OBJ } from './utils'
-import { createElement } from './h'
import { VNode, Slots, RenderNode, MountedVNode } from './vdom'
import {
Data,
- RenderFunction,
ComponentOptions,
ComponentPropsOptions,
- WatchOptions,
- RenderContext
+ WatchOptions
} from './componentOptions'
import { setupWatcher } from './componentWatch'
import { Autorun, DebuggerEvent, ComputedGetter } from '@vue/observer'
type Flatten<T> = { [K in keyof T]: T[K] }
+export type RenderFunction<P = Data> = (
+ props: P,
+ slots: Slots,
+ attrs: Data
+) => any
+
export interface ComponentClass extends Flatten<typeof InternalComponent> {
new <D = Data, P = Data>(): D & P & MountedComponent<D, P>
}
$children: MountedComponent[]
$options: ComponentOptions<D, P>
- render(h: createElement, ctx: RenderContext<P>): any
+ render(props: P, slots: Slots, attrs: Data): any
renderError?(e: Error): any
renderTracked?(e: DebuggerEvent): void
renderTriggered?(e: DebuggerEvent): void
-import { createElement } from './h'
-import { Slots } from './vdom'
-import { MountedComponent } from './component'
+import { MountedComponent, RenderFunction } from './component'
export type Data = Record<string, any>
-export interface RenderContext<P> {
- props: P
- slots: Slots
- attrs: Data
-}
-
-export interface RenderFunction<P = Data> {
- (h: createElement, ctx: RenderContext<P>): any
-}
-
export interface ComponentOptions<D = Data, P = Data> {
data?: () => Partial<D>
props?: ComponentPropsOptions<P>
for (const key in options) {
const value = options[key]
if (typeof value === 'function') {
- ;(ObjectComponent.prototype as any)[key] = value
+ ;(ObjectComponent.prototype as any)[key] =
+ key === 'render'
+ ? function() {
+ return value.call(this, h)
+ }
+ : value
}
if (key === 'computed') {
const isGet = typeof value === 'function'
-import { h } from './h'
import { autorun, stop } from '@vue/observer'
import { queueJob } from '@vue/scheduler'
import { VNodeFlags, ChildrenFlags } from './flags'
const render = tag as FunctionalComponent
const { props, attrs } = resolveProps(data, render.props)
const subTree = (vnode.children = normalizeComponentRoot(
- render(h, {
- props,
- slots: slots || EMPTY_OBJ,
- attrs: attrs || EMPTY_OBJ
- }),
+ render(props, slots || EMPTY_OBJ, attrs || EMPTY_OBJ),
vnode,
attrs,
render.inheritAttrs
if (shouldUpdate) {
const { props, attrs } = resolveProps(nextData, render.props)
const nextTree = (nextVNode.children = normalizeComponentRoot(
- render(h, {
- props,
- slots: nextSlots || EMPTY_OBJ,
- attrs: attrs || EMPTY_OBJ
- }),
+ render(props, nextSlots || EMPTY_OBJ, attrs || EMPTY_OBJ),
nextVNode,
attrs,
render.inheritAttrs
instance.$vnode = renderInstanceRoot(instance) as MountedVNode
mount(instance.$vnode, container, instance, isSVG, endNode)
parentVNode.el = instance.$vnode.el
+
if (__DEV__) {
// expose __vue__ for devtools
;(parentVNode.el as any).__vue__ = instance
}
+
instance._mounted = true
mountComponentInstanceCallbacks(instance, parentVNode.ref)
}
}
}
- render(_: any, { props, slots }: { props: any; slots: Slots }) {
+ render(props: any, slots: Slots) {
if (this.err || (this.timedOut && !this.comp)) {
const error =
this.err || new Error(`Async component timed out after ${timeout}ms.`)
beforeUpdate() {
this.updateValue()
}
- render(_: any, { slots }: { slots: Slots }) {
+ render(props: any, slots: Slots) {
return slots.default && slots.default()
}
}
}
export class Inject extends Component {
- render(_: any, { props, slots }: { props: any; slots: Slots }) {
+ render(props: any, slots: Slots) {
return slots.default && slots.default(contextStore[props.id])
}
}
this.keys.delete(key)
}
- render(_: any, { props, slots }: { props: KeepAliveProps; slots: Slots }) {
+ render(props: KeepAliveProps, slots: Slots) {
if (!slots.default) {
return
}