refactor(reactivity): make readonly non-tracking

This commit is contained in:
Evan You
2020-04-14 23:49:46 -04:00
parent 09b44e07cb
commit 3178504273
11 changed files with 110 additions and 250 deletions

View File

@@ -3,7 +3,8 @@ import {
reactive,
ReactiveEffect,
pauseTracking,
resetTracking
resetTracking,
shallowReadonly
} from '@vue/reactivity'
import {
ComponentPublicInstance,
@@ -347,7 +348,7 @@ function setupStatefulComponent(
setup,
instance,
ErrorCodes.SETUP_FUNCTION,
[instance.props, setupContext]
[__DEV__ ? shallowReadonly(instance.props) : instance.props, setupContext]
)
resetTracking()
currentInstance = null
@@ -479,17 +480,6 @@ function finishComponentSetup(
}
}
const slotsHandlers: ProxyHandler<InternalSlots> = {
set: () => {
warn(`setupContext.slots is readonly.`)
return false
},
deleteProperty: () => {
warn(`setupContext.slots is readonly.`)
return false
}
}
const attrHandlers: ProxyHandler<Data> = {
get: (target, key: string) => {
markAttrsAccessed()
@@ -514,7 +504,7 @@ function createSetupContext(instance: ComponentInternalInstance): SetupContext {
return new Proxy(instance.attrs, attrHandlers)
},
get slots() {
return new Proxy(instance.slots, slotsHandlers)
return shallowReadonly(instance.slots)
},
get emit() {
return (event: string, ...args: any[]) => instance.emit(event, ...args)