Skip to content

Commit

Permalink
feat: remove setupState reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbinBaauw committed Jul 12, 2020
1 parent 36acc2b commit d4653a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 4 additions & 5 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { VNode, VNodeChild, isVNode } from './vnode'
import {
reactive,
ReactiveEffect,
pauseTracking,
resetTracking,
Expand All @@ -9,11 +8,11 @@ import {
import {
CreateComponentPublicInstance,
ComponentPublicInstance,
PublicInstanceProxyHandlers,
RuntimeCompiledPublicInstanceProxyHandlers,
createRenderContext,
exposePropsOnRenderContext,
exposeSetupStateOnRenderContext
exposeSetupStateOnRenderContext,
RuntimeCompiledPublicInstanceProxyHandlers,
PublicInstanceProxyHandlers
} from './componentProxy'
import {
ComponentPropsOptions,
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 7 additions & 4 deletions packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
shallowReadonly,
ReactiveFlags,
track,
TrackOpTypes
TrackOpTypes,
unref,
isRef
} from '@vue/reactivity'
import {
ExtractComputedReturns,
Expand Down Expand Up @@ -227,7 +229,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
if (n !== undefined) {
switch (n) {
case AccessTypes.SETUP:
return setupState[key]
return unref(setupState[key])
case AccessTypes.DATA:
return data[key]
case AccessTypes.CONTEXT:
Expand All @@ -238,7 +240,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
}
} 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]
Expand Down Expand Up @@ -313,7 +315,8 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
): 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) {
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit d4653a9

Please sign in to comment.