vue3-yuanma/packages/runtime-core/src/compat/instance.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-04-05 22:13:29 +00:00
import { extend, NOOP } from '@vue/shared'
import { PublicPropertiesMap } from '../componentPublicInstance'
2021-04-06 20:51:11 +00:00
import { getInstanceChildren } from './children'
2021-04-05 22:13:29 +00:00
import { DeprecationTypes, warnDeprecation } from './deprecations'
2021-04-06 19:58:12 +00:00
import { off, on, once } from './eventEmitter'
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, {
$set: () => {
__DEV__ && warnDeprecation(DeprecationTypes.INSTANCE_SET)
return set
},
$delete: () => {
__DEV__ && warnDeprecation(DeprecationTypes.INSTANCE_DELETE)
return del
},
$mount: i => {
__DEV__ && warnDeprecation(DeprecationTypes.INSTANCE_MOUNT)
// root mount override from ./global.ts in installCompatMount
return i.ctx._compat_mount || NOOP
},
$destroy: i => {
__DEV__ && warnDeprecation(DeprecationTypes.INSTANCE_DESTROY)
// root destroy override from ./global.ts in installCompatMount
return i.ctx._compat_destroy || NOOP
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),
$children: getInstanceChildren
2021-04-05 22:13:29 +00:00
} as PublicPropertiesMap)
}