wip: template binding optimization

This commit is contained in:
Evan You
2020-07-10 22:12:25 -04:00
parent b51b79f5c4
commit b6cdd5621e
12 changed files with 81 additions and 30 deletions

View File

@@ -77,10 +77,8 @@ export interface ComponentInternalOptions {
__file?: string
}
export interface FunctionalComponent<
P = {},
E extends EmitsOptions = {}
> extends ComponentInternalOptions {
export interface FunctionalComponent<P = {}, E extends EmitsOptions = {}>
extends ComponentInternalOptions {
// use of any here is intentional so it can be a valid JSX Element constructor
(props: P, ctx: SetupContext<E>): any
props?: ComponentPropsOptions<P>
@@ -142,7 +140,12 @@ export interface SetupContext<E = ObjectEmitsOptions> {
export type InternalRenderFunction = {
(
ctx: ComponentPublicInstance,
cache: ComponentInternalInstance['renderCache']
cache: ComponentInternalInstance['renderCache'],
// for compiler-optimized bindings
$props: ComponentInternalInstance['props'],
$setup: ComponentInternalInstance['setupState'],
$data: ComponentInternalInstance['data'],
$options: ComponentInternalInstance['ctx']
): VNodeChild
_rc?: boolean // isRuntimeCompiled
}

View File

@@ -119,7 +119,12 @@ export interface ComponentOptionsBase<
ctx: any,
push: (item: any) => void,
parentInstance: ComponentInternalInstance,
attrs?: Data
attrs: Data | undefined,
// for compiler-optimized bindings
$props: ComponentInternalInstance['props'],
$setup: ComponentInternalInstance['setupState'],
$data: ComponentInternalInstance['data'],
$options: ComponentInternalInstance['ctx']
) => void
/**

View File

@@ -50,7 +50,11 @@ export function renderComponentRoot(
slots,
attrs,
emit,
renderCache
render,
renderCache,
data,
setupState,
ctx
} = instance
let result
@@ -65,7 +69,15 @@ export function renderComponentRoot(
// runtime-compiled render functions using `with` block.
const proxyToUse = withProxy || proxy
result = normalizeVNode(
instance.render!.call(proxyToUse, proxyToUse!, renderCache)
render!.call(
proxyToUse,
proxyToUse!,
renderCache,
props,
setupState,
data,
ctx
)
)
fallthroughAttrs = attrs
} else {