From: Evan You Date: Fri, 1 Mar 2019 18:47:28 +0000 (-0500) Subject: refactor: expose $self X-Git-Tag: v3.0.0-alpha.0~1009 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=66686f38a7f8ec113887e0889e0160e87916994b;p=thirdparty%2Fvuejs%2Fcore.git refactor: expose $self --- diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 6e00f3914c..0698dd2a6f 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -30,6 +30,7 @@ export interface Component

extends PublicInstanceMethods { readonly $options: ComponentOptions readonly $refs: Record readonly $proxy: this + readonly $self: this } interface PublicInstanceMethods { @@ -99,10 +100,10 @@ export interface ComponentInstance

$root: ComponentInstance $children: ComponentInstance[] $options: ComponentOptions + $self: ComponentInstance // on proxies only _update: ReactiveEffect _queueJob: ((fn: () => void) => void) - _self: ComponentInstance // on proxies only } // actual implementation of the component diff --git a/packages/runtime-core/src/componentInstance.ts b/packages/runtime-core/src/componentInstance.ts index 4e485680c7..51c6ed4b5e 100644 --- a/packages/runtime-core/src/componentInstance.ts +++ b/packages/runtime-core/src/componentInstance.ts @@ -91,7 +91,7 @@ export function initializeComponentInstance(instance: ComponentInstance) { } export function teardownComponentInstance(instance: ComponentInstance) { - const parentComponent = instance.$parent && instance.$parent._self + const parentComponent = instance.$parent && instance.$parent.$self if (parentComponent && !parentComponent._unmounted) { parentComponent.$children.splice( parentComponent.$children.indexOf(instance.$proxy), diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 4ebbbf7915..40762e8eb1 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -22,7 +22,7 @@ function getBoundMethod(fn: Function, target: any, receiver: any): Function { const renderProxyHandlers = { get(target: ComponentInstance, 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 diff --git a/packages/runtime-core/src/errorHandling.ts b/packages/runtime-core/src/errorHandling.ts index 2d42768481..4e61b60165 100644 --- a/packages/runtime-core/src/errorHandling.ts +++ b/packages/runtime-core/src/errorHandling.ts @@ -56,11 +56,11 @@ export function callLifecycleHookWithHandler( const res = hook.call(instanceProxy, arg) if (res && !res._isVue && typeof res.then === 'function') { ;(res as Promise).catch(err => { - handleError(err, instanceProxy._self, type) + handleError(err, instanceProxy.$self, type) }) } } catch (err) { - handleError(err, instanceProxy._self, type) + handleError(err, instanceProxy.$self, type) } } @@ -88,7 +88,7 @@ export function handleError( cur = (instance as ComponentInstance).$parent } while (cur) { - cur = cur._self + cur = cur.$self const handler = cur.errorCaptured if (handler) { try { @@ -116,8 +116,9 @@ function logError(err: Error, type: ErrorTypes, contextVNode: VNode | null) { } if (/private field/.test(err.message)) { warn( - `Private fields are not supported in component classes because they ` + - `cannot be tunneled through Proxies.` + `Private fields cannot be accessed directly on \`this\` in a component ` + + `class because they cannot be tunneled through Proxies. ` + + `Use \`this.$self.#field\` instead.` ) } else { warn(`Unhandled error${info ? ` ${info}` : ``}`)