refactor(runtime-core): make setup attrs proxy dev only

This commit is contained in:
Evan You
2020-04-06 17:57:27 -04:00
parent ec4a4c1e06
commit c5f0f63b91
5 changed files with 30 additions and 8 deletions

View File

@@ -504,12 +504,25 @@ const SetupProxyHandlers: { [key: string]: ProxyHandler<any> } = {}
}
})
const attrsProxyHandlers: ProxyHandler<Data> = {
get(target, key: string) {
if (__DEV__) {
markAttrsAccessed()
}
return target[key]
},
set: () => false,
deleteProperty: () => false
}
function createSetupContext(instance: ComponentInternalInstance): SetupContext {
const context = {
// attrs & slots are non-reactive, but they need to always expose
// the latest values (instance.xxx may get replaced during updates) so we
// need to expose them through a proxy
attrs: new Proxy(instance, SetupProxyHandlers.attrs),
attrs: __DEV__
? new Proxy(instance.attrs, attrsProxyHandlers)
: instance.attrs,
slots: new Proxy(instance, SetupProxyHandlers.slots),
get emit() {
return instance.emit