From d4653a98782e1ec616fc68a03a6761585b20e0ff Mon Sep 17 00:00:00 2001 From: Robbin Baauw Date: Sun, 12 Jul 2020 10:11:42 +0200 Subject: [PATCH] feat: remove setupState reactive --- packages/runtime-core/src/component.ts | 9 ++++----- packages/runtime-core/src/componentProxy.ts | 11 +++++++---- packages/runtime-core/src/renderer.ts | 7 ++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index b467d579481..a047140fb5a 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -1,6 +1,5 @@ import { VNode, VNodeChild, isVNode } from './vnode' import { - reactive, ReactiveEffect, pauseTracking, resetTracking, @@ -9,11 +8,11 @@ import { import { CreateComponentPublicInstance, ComponentPublicInstance, - PublicInstanceProxyHandlers, - RuntimeCompiledPublicInstanceProxyHandlers, createRenderContext, exposePropsOnRenderContext, - exposeSetupStateOnRenderContext + exposeSetupStateOnRenderContext, + RuntimeCompiledPublicInstanceProxyHandlers, + PublicInstanceProxyHandlers } from './componentProxy' import { ComponentPropsOptions, @@ -535,7 +534,7 @@ export function handleSetupResult( } // setup returned bindings. // assuming a render function compiled from template is present. - instance.setupState = reactive(setupResult) + instance.setupState = setupResult if (__DEV__) { exposeSetupStateOnRenderContext(instance) } diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 9ea672aa2b5..83e5c8de83e 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -15,7 +15,9 @@ import { shallowReadonly, ReactiveFlags, track, - TrackOpTypes + TrackOpTypes, + unref, + isRef } from '@vue/reactivity' import { ExtractComputedReturns, @@ -227,7 +229,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { if (n !== undefined) { switch (n) { case AccessTypes.SETUP: - return setupState[key] + return unref(setupState[key]) case AccessTypes.DATA: return data[key] case AccessTypes.CONTEXT: @@ -238,7 +240,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { } } else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) { accessCache![key] = AccessTypes.SETUP - return setupState[key] + return unref(setupState[key]) } else if (data !== EMPTY_OBJ && hasOwn(data, key)) { accessCache![key] = AccessTypes.DATA return data[key] @@ -313,7 +315,8 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { ): boolean { const { data, setupState, ctx } = instance if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) { - setupState[key] = value + let setupValue = setupState[key] + isRef(setupValue) ? (setupValue.value = value) : (setupState[key] = value) } else if (data !== EMPTY_OBJ && hasOwn(data, key)) { data[key] = value } else if (key in instance.props) { diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index 0b3bd8318fe..e6341046985 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -320,7 +320,12 @@ export const setRef = ( refs[ref] = value if (hasOwn(setupState, ref)) { queuePostRenderEffect(() => { - setupState[ref] = value + const setupStateRef = setupState[ref] + if (isRef(setupStateRef)) { + setupStateRef.value = value + } else { + setupState[ref] = value + } }, parentSuspense) } } else if (isRef(ref)) {