refactor(reactivity): make readonly non-tracking
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user