refactor: revert render fn signature
This commit is contained in:
parent
65033cec9d
commit
03fd4da21d
@ -1,13 +1,10 @@
|
||||
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'
|
||||
@ -16,6 +13,12 @@ import { ErrorTypes } from './errorHandling'
|
||||
|
||||
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>
|
||||
}
|
||||
@ -42,7 +45,7 @@ export interface MountedComponent<D = Data, P = Data>
|
||||
$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
|
||||
|
@ -1,19 +1,7 @@
|
||||
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>
|
||||
|
@ -179,7 +179,12 @@ export function createComponentClassFromOptions(
|
||||
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'
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { h } from './h'
|
||||
import { autorun, stop } from '@vue/observer'
|
||||
import { queueJob } from '@vue/scheduler'
|
||||
import { VNodeFlags, ChildrenFlags } from './flags'
|
||||
@ -238,11 +237,7 @@ export function createRenderer(options: RendererOptions) {
|
||||
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
|
||||
@ -530,11 +525,7 @@ export function createRenderer(options: RendererOptions) {
|
||||
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
|
||||
@ -1200,10 +1191,12 @@ export function createRenderer(options: RendererOptions) {
|
||||
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)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export function createAsyncComponent(
|
||||
}
|
||||
}
|
||||
|
||||
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.`)
|
||||
|
@ -31,7 +31,7 @@ export class Provide extends Component {
|
||||
beforeUpdate() {
|
||||
this.updateValue()
|
||||
}
|
||||
render(_: any, { slots }: { slots: Slots }) {
|
||||
render(props: any, slots: Slots) {
|
||||
return slots.default && slots.default()
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ Provide.options = {
|
||||
}
|
||||
|
||||
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])
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ export class KeepAlive extends Component<{}, KeepAliveProps> {
|
||||
this.keys.delete(key)
|
||||
}
|
||||
|
||||
render(_: any, { props, slots }: { props: KeepAliveProps; slots: Slots }) {
|
||||
render(props: KeepAliveProps, slots: Slots) {
|
||||
if (!slots.default) {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user