2021-04-05 22:13:29 +00:00
|
|
|
import { extend, NOOP } from '@vue/shared'
|
|
|
|
import { PublicPropertiesMap } from '../componentPublicInstance'
|
2021-04-08 14:06:12 +00:00
|
|
|
import { getCompatChildren } from './instanceChildren'
|
2021-04-10 03:51:50 +00:00
|
|
|
import {
|
2021-04-12 22:47:50 +00:00
|
|
|
DeprecationTypes,
|
2021-04-10 03:51:50 +00:00
|
|
|
assertCompatEnabled,
|
|
|
|
checkCompatEnabled,
|
|
|
|
isCompatEnabled
|
|
|
|
} from './compatConfig'
|
2021-04-08 14:06:12 +00:00
|
|
|
import { off, on, once } from './instanceEventEmitter'
|
|
|
|
import { getCompatListeners } from './instanceListeners'
|
2021-04-08 14:41:25 +00:00
|
|
|
import { shallowReadonly } from '@vue/reactivity'
|
2021-04-09 22:52:14 +00:00
|
|
|
import { legacySlotProxyHandlers } from './component'
|
2021-04-05 22:13:29 +00:00
|
|
|
|
|
|
|
export function installCompatInstanceProperties(map: PublicPropertiesMap) {
|
|
|
|
const set = (target: any, key: any, val: any) => {
|
|
|
|
target[key] = val
|
|
|
|
}
|
|
|
|
|
|
|
|
const del = (target: any, key: any) => {
|
|
|
|
delete target[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
extend(map, {
|
2021-04-09 22:52:14 +00:00
|
|
|
$set: i => {
|
|
|
|
assertCompatEnabled(DeprecationTypes.INSTANCE_SET, i)
|
2021-04-05 22:13:29 +00:00
|
|
|
return set
|
|
|
|
},
|
2021-04-08 14:21:14 +00:00
|
|
|
|
2021-04-09 22:52:14 +00:00
|
|
|
$delete: i => {
|
|
|
|
assertCompatEnabled(DeprecationTypes.INSTANCE_DELETE, i)
|
2021-04-05 22:13:29 +00:00
|
|
|
return del
|
|
|
|
},
|
2021-04-08 14:21:14 +00:00
|
|
|
|
2021-04-05 22:13:29 +00:00
|
|
|
$mount: i => {
|
2021-04-09 22:52:14 +00:00
|
|
|
assertCompatEnabled(
|
|
|
|
DeprecationTypes.GLOBAL_MOUNT,
|
|
|
|
null /* this warning is global */
|
|
|
|
)
|
2021-04-05 22:13:29 +00:00
|
|
|
// root mount override from ./global.ts in installCompatMount
|
|
|
|
return i.ctx._compat_mount || NOOP
|
|
|
|
},
|
2021-04-08 14:21:14 +00:00
|
|
|
|
2021-04-05 22:13:29 +00:00
|
|
|
$destroy: i => {
|
2021-04-09 22:52:14 +00:00
|
|
|
assertCompatEnabled(DeprecationTypes.INSTANCE_DESTROY, i)
|
2021-04-05 22:13:29 +00:00
|
|
|
// root destroy override from ./global.ts in installCompatMount
|
|
|
|
return i.ctx._compat_destroy || NOOP
|
2021-04-06 19:58:12 +00:00
|
|
|
},
|
2021-04-08 14:21:14 +00:00
|
|
|
|
2021-04-09 22:52:14 +00:00
|
|
|
// overrides existing accessor
|
|
|
|
$slots: i => {
|
2021-04-11 15:15:40 +00:00
|
|
|
if (
|
|
|
|
isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, i) &&
|
|
|
|
i.render &&
|
|
|
|
i.render._compatWrapped
|
|
|
|
) {
|
2021-04-09 22:52:14 +00:00
|
|
|
return new Proxy(i.slots, legacySlotProxyHandlers)
|
|
|
|
}
|
2021-04-10 03:51:50 +00:00
|
|
|
return __DEV__ ? shallowReadonly(i.slots) : i.slots
|
2021-04-09 22:52:14 +00:00
|
|
|
},
|
|
|
|
|
2021-04-08 14:21:14 +00:00
|
|
|
$scopedSlots: i => {
|
2021-04-09 22:52:14 +00:00
|
|
|
assertCompatEnabled(DeprecationTypes.INSTANCE_SCOPED_SLOTS, i)
|
2021-04-08 14:41:25 +00:00
|
|
|
return __DEV__ ? shallowReadonly(i.slots) : i.slots
|
|
|
|
},
|
|
|
|
|
|
|
|
// overrides existing accessor
|
|
|
|
$attrs: i => {
|
|
|
|
if (__DEV__ && i.type.inheritAttrs === false) {
|
2021-04-10 03:51:50 +00:00
|
|
|
checkCompatEnabled(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, i)
|
2021-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
return __DEV__ ? shallowReadonly(i.attrs) : i.attrs
|
2021-04-08 14:21:14 +00:00
|
|
|
},
|
|
|
|
|
2021-04-06 19:58:12 +00:00
|
|
|
$on: i => on.bind(null, i),
|
|
|
|
$once: i => once.bind(null, i),
|
2021-04-06 20:51:11 +00:00
|
|
|
$off: i => off.bind(null, i),
|
2021-04-08 14:21:14 +00:00
|
|
|
|
2021-04-08 14:06:12 +00:00
|
|
|
$children: getCompatChildren,
|
|
|
|
$listeners: getCompatListeners
|
2021-04-05 22:13:29 +00:00
|
|
|
} as PublicPropertiesMap)
|
|
|
|
}
|