refactor: return Proxy from base class constructor

This commit is contained in:
Evan You
2019-03-05 16:24:07 -05:00
parent c335939dcf
commit ec0ccd2337
9 changed files with 62 additions and 56 deletions

View File

@@ -22,7 +22,7 @@ function getBoundMethod(fn: Function, target: any, receiver: any): Function {
const renderProxyHandlers = {
get(target: ComponentInstance<any, any>, key: string, receiver: any) {
let i: any
if (key === '$self') {
if (key === '_self') {
return target
} else if ((i = target._rawData) !== null && i.hasOwnProperty(key)) {
// data
@@ -86,6 +86,11 @@ const renderProxyHandlers = {
}
}
export function createRenderProxy(instance: any): ComponentInstance {
return new Proxy(instance, renderProxyHandlers) as ComponentInstance
export type ComponentProxy<T = ComponentInstance> = T & { _self: T }
export function createRenderProxy<T extends ComponentInstance>(
instance: T
): ComponentProxy<T> {
debugger
return new Proxy(instance, renderProxyHandlers) as any
}