fix: simplify and use correct ctx in withCtx

This commit is contained in:
Evan You
2020-03-16 13:06:37 -04:00
parent fd3418d79d
commit 4dc8ffc378
8 changed files with 44 additions and 45 deletions

View File

@@ -2,7 +2,6 @@
// These are only used in esm-bundler builds, but since exports cannot be
// conditional, we can only drop inner implementations in non-bundler builds.
import { ComponentInternalInstance } from '../component'
import { withCtx } from './withRenderContext'
export let currentScopeId: string | null = null
@@ -23,14 +22,13 @@ export function popScopeId() {
export function withScopeId(id: string): <T extends Function>(fn: T) => T {
if (__BUNDLER__) {
return ((fn: Function, ctx?: ComponentInternalInstance) => {
return withCtx(function(this: any) {
return ((fn: Function) =>
withCtx(function(this: any) {
pushScopeId(id)
const res = fn.apply(this, arguments)
popScopeId()
return res
}, ctx)
}) as any
})) as any
} else {
return undefined as any
}

View File

@@ -1,13 +1,13 @@
import { Slot } from '../componentSlots'
import { ComponentInternalInstance } from '../component'
import {
setCurrentRenderingInstance,
currentRenderingInstance
} from '../componentRenderUtils'
import { ComponentInternalInstance } from '../component'
export function withCtx(
fn: Slot,
ctx: ComponentInternalInstance | null | undefined
ctx: ComponentInternalInstance | null = currentRenderingInstance
) {
if (!ctx) return fn
return function renderFnWithContext() {