refactor: revert render fn signature
This commit is contained in:
parent
65033cec9d
commit
03fd4da21d
@ -1,13 +1,10 @@
|
|||||||
import { EMPTY_OBJ } from './utils'
|
import { EMPTY_OBJ } from './utils'
|
||||||
import { createElement } from './h'
|
|
||||||
import { VNode, Slots, RenderNode, MountedVNode } from './vdom'
|
import { VNode, Slots, RenderNode, MountedVNode } from './vdom'
|
||||||
import {
|
import {
|
||||||
Data,
|
Data,
|
||||||
RenderFunction,
|
|
||||||
ComponentOptions,
|
ComponentOptions,
|
||||||
ComponentPropsOptions,
|
ComponentPropsOptions,
|
||||||
WatchOptions,
|
WatchOptions
|
||||||
RenderContext
|
|
||||||
} from './componentOptions'
|
} from './componentOptions'
|
||||||
import { setupWatcher } from './componentWatch'
|
import { setupWatcher } from './componentWatch'
|
||||||
import { Autorun, DebuggerEvent, ComputedGetter } from '@vue/observer'
|
import { Autorun, DebuggerEvent, ComputedGetter } from '@vue/observer'
|
||||||
@ -16,6 +13,12 @@ import { ErrorTypes } from './errorHandling'
|
|||||||
|
|
||||||
type Flatten<T> = { [K in keyof T]: T[K] }
|
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> {
|
export interface ComponentClass extends Flatten<typeof InternalComponent> {
|
||||||
new <D = Data, P = Data>(): D & P & MountedComponent<D, P>
|
new <D = Data, P = Data>(): D & P & MountedComponent<D, P>
|
||||||
}
|
}
|
||||||
@ -42,7 +45,7 @@ export interface MountedComponent<D = Data, P = Data>
|
|||||||
$children: MountedComponent[]
|
$children: MountedComponent[]
|
||||||
$options: ComponentOptions<D, P>
|
$options: ComponentOptions<D, P>
|
||||||
|
|
||||||
render(h: createElement, ctx: RenderContext<P>): any
|
render(props: P, slots: Slots, attrs: Data): any
|
||||||
renderError?(e: Error): any
|
renderError?(e: Error): any
|
||||||
renderTracked?(e: DebuggerEvent): void
|
renderTracked?(e: DebuggerEvent): void
|
||||||
renderTriggered?(e: DebuggerEvent): void
|
renderTriggered?(e: DebuggerEvent): void
|
||||||
|
@ -1,19 +1,7 @@
|
|||||||
import { createElement } from './h'
|
import { MountedComponent, RenderFunction } from './component'
|
||||||
import { Slots } from './vdom'
|
|
||||||
import { MountedComponent } from './component'
|
|
||||||
|
|
||||||
export type Data = Record<string, any>
|
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> {
|
export interface ComponentOptions<D = Data, P = Data> {
|
||||||
data?: () => Partial<D>
|
data?: () => Partial<D>
|
||||||
props?: ComponentPropsOptions<P>
|
props?: ComponentPropsOptions<P>
|
||||||
|
@ -179,7 +179,12 @@ export function createComponentClassFromOptions(
|
|||||||
for (const key in options) {
|
for (const key in options) {
|
||||||
const value = options[key]
|
const value = options[key]
|
||||||
if (typeof value === 'function') {
|
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') {
|
if (key === 'computed') {
|
||||||
const isGet = typeof value === 'function'
|
const isGet = typeof value === 'function'
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { h } from './h'
|
|
||||||
import { autorun, stop } from '@vue/observer'
|
import { autorun, stop } from '@vue/observer'
|
||||||
import { queueJob } from '@vue/scheduler'
|
import { queueJob } from '@vue/scheduler'
|
||||||
import { VNodeFlags, ChildrenFlags } from './flags'
|
import { VNodeFlags, ChildrenFlags } from './flags'
|
||||||
@ -238,11 +237,7 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
const render = tag as FunctionalComponent
|
const render = tag as FunctionalComponent
|
||||||
const { props, attrs } = resolveProps(data, render.props)
|
const { props, attrs } = resolveProps(data, render.props)
|
||||||
const subTree = (vnode.children = normalizeComponentRoot(
|
const subTree = (vnode.children = normalizeComponentRoot(
|
||||||
render(h, {
|
render(props, slots || EMPTY_OBJ, attrs || EMPTY_OBJ),
|
||||||
props,
|
|
||||||
slots: slots || EMPTY_OBJ,
|
|
||||||
attrs: attrs || EMPTY_OBJ
|
|
||||||
}),
|
|
||||||
vnode,
|
vnode,
|
||||||
attrs,
|
attrs,
|
||||||
render.inheritAttrs
|
render.inheritAttrs
|
||||||
@ -530,11 +525,7 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
const { props, attrs } = resolveProps(nextData, render.props)
|
const { props, attrs } = resolveProps(nextData, render.props)
|
||||||
const nextTree = (nextVNode.children = normalizeComponentRoot(
|
const nextTree = (nextVNode.children = normalizeComponentRoot(
|
||||||
render(h, {
|
render(props, nextSlots || EMPTY_OBJ, attrs || EMPTY_OBJ),
|
||||||
props,
|
|
||||||
slots: nextSlots || EMPTY_OBJ,
|
|
||||||
attrs: attrs || EMPTY_OBJ
|
|
||||||
}),
|
|
||||||
nextVNode,
|
nextVNode,
|
||||||
attrs,
|
attrs,
|
||||||
render.inheritAttrs
|
render.inheritAttrs
|
||||||
@ -1200,10 +1191,12 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
instance.$vnode = renderInstanceRoot(instance) as MountedVNode
|
instance.$vnode = renderInstanceRoot(instance) as MountedVNode
|
||||||
mount(instance.$vnode, container, instance, isSVG, endNode)
|
mount(instance.$vnode, container, instance, isSVG, endNode)
|
||||||
parentVNode.el = instance.$vnode.el
|
parentVNode.el = instance.$vnode.el
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
// expose __vue__ for devtools
|
// expose __vue__ for devtools
|
||||||
;(parentVNode.el as any).__vue__ = instance
|
;(parentVNode.el as any).__vue__ = instance
|
||||||
}
|
}
|
||||||
|
|
||||||
instance._mounted = true
|
instance._mounted = true
|
||||||
mountComponentInstanceCallbacks(instance, parentVNode.ref)
|
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)) {
|
if (this.err || (this.timedOut && !this.comp)) {
|
||||||
const error =
|
const error =
|
||||||
this.err || new Error(`Async component timed out after ${timeout}ms.`)
|
this.err || new Error(`Async component timed out after ${timeout}ms.`)
|
||||||
|
@ -31,7 +31,7 @@ export class Provide extends Component {
|
|||||||
beforeUpdate() {
|
beforeUpdate() {
|
||||||
this.updateValue()
|
this.updateValue()
|
||||||
}
|
}
|
||||||
render(_: any, { slots }: { slots: Slots }) {
|
render(props: any, slots: Slots) {
|
||||||
return slots.default && slots.default()
|
return slots.default && slots.default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ Provide.options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Inject extends Component {
|
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])
|
return slots.default && slots.default(contextStore[props.id])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ export class KeepAlive extends Component<{}, KeepAliveProps> {
|
|||||||
this.keys.delete(key)
|
this.keys.delete(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
render(_: any, { props, slots }: { props: KeepAliveProps; slots: Slots }) {
|
render(props: KeepAliveProps, slots: Slots) {
|
||||||
if (!slots.default) {
|
if (!slots.default) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user