feat(runtime-core): set context for manual slot functions as well

This commit is contained in:
Evan You
2020-03-16 12:20:52 -04:00
parent ecd7ce60d5
commit 8a58dce603
5 changed files with 37 additions and 19 deletions

View File

@@ -24,13 +24,12 @@ export function popScopeId() {
export function withScopeId(id: string): <T extends Function>(fn: T) => T {
if (__BUNDLER__) {
return ((fn: Function, ctx?: ComponentInternalInstance) => {
function renderWithId(this: any) {
return withCtx(function(this: any) {
pushScopeId(id)
const res = fn.apply(this, arguments)
popScopeId()
return res
}
return ctx ? withCtx(renderWithId, ctx) : renderWithId
}, ctx)
}) as any
} else {
return undefined as any

View File

@@ -5,7 +5,11 @@ import {
currentRenderingInstance
} from '../componentRenderUtils'
export function withCtx(fn: Slot, ctx: ComponentInternalInstance) {
export function withCtx(
fn: Slot,
ctx: ComponentInternalInstance | null | undefined
) {
if (!ctx) return fn
return function renderFnWithContext() {
const owner = currentRenderingInstance
setCurrentRenderingInstance(ctx)