refactor: adjust render fn signature
This commit is contained in:
parent
172b7f5cf7
commit
88be7ecd37
@ -31,14 +31,14 @@ describe('attribute fallthrough', () => {
|
||||
updated() {
|
||||
childUpdated()
|
||||
}
|
||||
render(props: any) {
|
||||
render() {
|
||||
return h(
|
||||
'div',
|
||||
{
|
||||
class: 'c2',
|
||||
style: { fontWeight: 'bold' }
|
||||
},
|
||||
props.foo
|
||||
this.$props.foo
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -103,14 +103,14 @@ describe('attribute fallthrough', () => {
|
||||
updated() {
|
||||
childUpdated()
|
||||
}
|
||||
render(props: any) {
|
||||
render() {
|
||||
return h(
|
||||
'div',
|
||||
{
|
||||
class: 'c2',
|
||||
style: { fontWeight: 'bold' }
|
||||
},
|
||||
props.foo
|
||||
this.$props.foo
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
import { EMPTY_OBJ } from './utils'
|
||||
import { createElement } from './h'
|
||||
import { VNode, Slots, RenderNode, MountedVNode } from './vdom'
|
||||
import {
|
||||
Data,
|
||||
RenderFunction,
|
||||
ComponentOptions,
|
||||
ComponentPropsOptions,
|
||||
WatchOptions
|
||||
WatchOptions,
|
||||
RenderContext
|
||||
} from './componentOptions'
|
||||
import { setupWatcher } from './componentWatch'
|
||||
import { Autorun, DebuggerEvent, ComputedGetter } from '@vue/observer'
|
||||
@ -40,7 +42,7 @@ export interface MountedComponent<D = Data, P = Data>
|
||||
$children: MountedComponent[]
|
||||
$options: ComponentOptions<D, P>
|
||||
|
||||
render(props: P, slots: Slots, attrs: Data): any
|
||||
render(h: createElement, ctx: RenderContext<P>): any
|
||||
renderError?(e: Error): any
|
||||
renderTracked?(e: DebuggerEvent): void
|
||||
renderTriggered?(e: DebuggerEvent): void
|
||||
|
@ -1,10 +1,17 @@
|
||||
import { createElement } from './h'
|
||||
import { Slots } from './vdom'
|
||||
import { MountedComponent } from './component'
|
||||
|
||||
export type Data = Record<string, any>
|
||||
|
||||
export interface RenderContext<P> {
|
||||
props: P
|
||||
slots: Slots
|
||||
attrs: Data
|
||||
}
|
||||
|
||||
export interface RenderFunction<P = Data> {
|
||||
(props: P, slots: Slots, attrs: Data): any
|
||||
(h: createElement, ctx: RenderContext<P>): any
|
||||
}
|
||||
|
||||
export interface ComponentOptions<D = Data, P = Data> {
|
||||
|
@ -56,12 +56,11 @@ export function createComponentInstance(
|
||||
export function renderInstanceRoot(instance: MountedComponent): VNode {
|
||||
let vnode
|
||||
try {
|
||||
vnode = instance.render.call(
|
||||
instance.$proxy,
|
||||
instance.$props,
|
||||
instance.$slots,
|
||||
instance.$attrs
|
||||
)
|
||||
vnode = instance.render.call(instance.$proxy, h, {
|
||||
props: instance.$props,
|
||||
slots: instance.$slots,
|
||||
attrs: instance.$attrs
|
||||
})
|
||||
} catch (e1) {
|
||||
handleError(e1, instance, ErrorTypes.RENDER)
|
||||
if (__DEV__ && instance.renderError) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { h } from './h'
|
||||
import { autorun, stop } from '@vue/observer'
|
||||
import { queueJob } from '@vue/scheduler'
|
||||
import { VNodeFlags, ChildrenFlags } from './flags'
|
||||
@ -237,7 +238,11 @@ export function createRenderer(options: RendererOptions) {
|
||||
const render = tag as FunctionalComponent
|
||||
const { props, attrs } = resolveProps(data, render.props)
|
||||
const subTree = (vnode.children = normalizeComponentRoot(
|
||||
render(props, slots || EMPTY_OBJ, attrs || EMPTY_OBJ),
|
||||
render(h, {
|
||||
props,
|
||||
slots: slots || EMPTY_OBJ,
|
||||
attrs: attrs || EMPTY_OBJ
|
||||
}),
|
||||
vnode,
|
||||
attrs,
|
||||
render.inheritAttrs
|
||||
@ -525,7 +530,11 @@ export function createRenderer(options: RendererOptions) {
|
||||
if (shouldUpdate) {
|
||||
const { props, attrs } = resolveProps(nextData, render.props)
|
||||
const nextTree = (nextVNode.children = normalizeComponentRoot(
|
||||
render(props, nextSlots || EMPTY_OBJ, attrs || EMPTY_OBJ),
|
||||
render(h, {
|
||||
props,
|
||||
slots: nextSlots || EMPTY_OBJ,
|
||||
attrs: attrs || EMPTY_OBJ
|
||||
}),
|
||||
nextVNode,
|
||||
attrs,
|
||||
render.inheritAttrs
|
||||
|
@ -58,10 +58,8 @@ export function handleError(
|
||||
function logError(err: Error, instance: MountedComponent, type: ErrorTypes) {
|
||||
if (__DEV__) {
|
||||
const info = ErrorTypeStrings[type]
|
||||
console.warn(
|
||||
`Unhandled error${info ? ` in ${info}` : ``}: "${err.toString()}"`,
|
||||
instance
|
||||
)
|
||||
console.warn(`Unhandled error${info ? ` in ${info}` : ``}:`)
|
||||
console.error(err)
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user