wip: more compat tweaks
This commit is contained in:
parent
12abd4af85
commit
98bc9a26e9
@ -36,6 +36,7 @@ import { queuePostRenderEffect } from './renderer'
|
|||||||
import { warn } from './warning'
|
import { warn } from './warning'
|
||||||
import { DeprecationTypes } from './compat/compatConfig'
|
import { DeprecationTypes } from './compat/compatConfig'
|
||||||
import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
|
import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
|
||||||
|
import { ObjectWatchOptionItem } from './componentOptions'
|
||||||
|
|
||||||
export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void
|
export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void
|
||||||
|
|
||||||
@ -354,7 +355,7 @@ function doWatch(
|
|||||||
export function instanceWatch(
|
export function instanceWatch(
|
||||||
this: ComponentInternalInstance,
|
this: ComponentInternalInstance,
|
||||||
source: string | Function,
|
source: string | Function,
|
||||||
cb: WatchCallback,
|
value: WatchCallback | ObjectWatchOptionItem,
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): WatchStopHandle {
|
): WatchStopHandle {
|
||||||
const publicThis = this.proxy as any
|
const publicThis = this.proxy as any
|
||||||
@ -363,6 +364,13 @@ export function instanceWatch(
|
|||||||
? createPathGetter(publicThis, source)
|
? createPathGetter(publicThis, source)
|
||||||
: () => publicThis[source]
|
: () => publicThis[source]
|
||||||
: source.bind(publicThis)
|
: source.bind(publicThis)
|
||||||
|
let cb
|
||||||
|
if (isFunction(value)) {
|
||||||
|
cb = value
|
||||||
|
} else {
|
||||||
|
cb = value.handler as Function
|
||||||
|
options = value
|
||||||
|
}
|
||||||
return doWatch(getter, cb.bind(publicThis), options, this)
|
return doWatch(getter, cb.bind(publicThis), options, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,8 @@ export function createCompatVue(
|
|||||||
} as any
|
} as any
|
||||||
|
|
||||||
const singletonApp = createApp({})
|
const singletonApp = createApp({})
|
||||||
|
// @ts-ignore
|
||||||
|
singletonApp.prototype = singletonApp.config.globalProperties
|
||||||
|
|
||||||
function createCompatApp(options: ComponentOptions = {}, Ctor: any) {
|
function createCompatApp(options: ComponentOptions = {}, Ctor: any) {
|
||||||
assertCompatEnabled(DeprecationTypes.GLOBAL_MOUNT, null)
|
assertCompatEnabled(DeprecationTypes.GLOBAL_MOUNT, null)
|
||||||
@ -145,7 +147,10 @@ export function createCompatVue(
|
|||||||
|
|
||||||
// copy prototype augmentations as config.globalProperties
|
// copy prototype augmentations as config.globalProperties
|
||||||
if (isCompatEnabled(DeprecationTypes.GLOBAL_PROTOTYPE, null)) {
|
if (isCompatEnabled(DeprecationTypes.GLOBAL_PROTOTYPE, null)) {
|
||||||
app.config.globalProperties = Ctor.prototype
|
app.config.globalProperties = extend(
|
||||||
|
Object.create(Ctor.prototype),
|
||||||
|
singletonApp.config.globalProperties
|
||||||
|
)
|
||||||
}
|
}
|
||||||
let hasPrototypeAugmentations = false
|
let hasPrototypeAugmentations = false
|
||||||
for (const key in Ctor.prototype) {
|
for (const key in Ctor.prototype) {
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
import { extend, NOOP, toDisplayString, toNumber } from '@vue/shared'
|
import {
|
||||||
|
extend,
|
||||||
|
looseEqual,
|
||||||
|
looseIndexOf,
|
||||||
|
NOOP,
|
||||||
|
toDisplayString,
|
||||||
|
toNumber
|
||||||
|
} from '@vue/shared'
|
||||||
import { PublicPropertiesMap } from '../componentPublicInstance'
|
import { PublicPropertiesMap } from '../componentPublicInstance'
|
||||||
import { getCompatChildren } from './instanceChildren'
|
import { getCompatChildren } from './instanceChildren'
|
||||||
import {
|
import {
|
||||||
@ -14,13 +21,17 @@ import { compatH } from './renderFn'
|
|||||||
import { createCommentVNode, createTextVNode } from '../vnode'
|
import { createCommentVNode, createTextVNode } from '../vnode'
|
||||||
import { renderList } from '../helpers/renderList'
|
import { renderList } from '../helpers/renderList'
|
||||||
import {
|
import {
|
||||||
|
legacyBindDynamicKeys,
|
||||||
legacyBindObjectListeners,
|
legacyBindObjectListeners,
|
||||||
legacyBindObjectProps,
|
legacyBindObjectProps,
|
||||||
legacyCheckKeyCodes,
|
legacyCheckKeyCodes,
|
||||||
|
legacyMarkOnce,
|
||||||
|
legacyPrependModifier,
|
||||||
legacyRenderSlot,
|
legacyRenderSlot,
|
||||||
legacyRenderStatic,
|
legacyRenderStatic,
|
||||||
legacyresolveScopedSlots
|
legacyresolveScopedSlots
|
||||||
} from './renderHelpers'
|
} from './renderHelpers'
|
||||||
|
import { resolveFilter } from '../helpers/resolveAssets'
|
||||||
|
|
||||||
export function installCompatInstanceProperties(map: PublicPropertiesMap) {
|
export function installCompatInstanceProperties(map: PublicPropertiesMap) {
|
||||||
const set = (target: any, key: any, val: any) => {
|
const set = (target: any, key: any, val: any) => {
|
||||||
@ -85,16 +96,22 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
|
|||||||
$createElement: () => compatH,
|
$createElement: () => compatH,
|
||||||
_self: i => i.proxy,
|
_self: i => i.proxy,
|
||||||
_c: () => compatH,
|
_c: () => compatH,
|
||||||
|
_o: () => legacyMarkOnce,
|
||||||
_n: () => toNumber,
|
_n: () => toNumber,
|
||||||
_s: () => toDisplayString,
|
_s: () => toDisplayString,
|
||||||
_l: () => renderList,
|
_l: () => renderList,
|
||||||
_t: i => legacyRenderSlot.bind(null, i),
|
_t: i => legacyRenderSlot.bind(null, i),
|
||||||
_b: () => legacyBindObjectProps,
|
_q: () => looseEqual,
|
||||||
_e: () => createCommentVNode,
|
_i: () => looseIndexOf,
|
||||||
_v: () => createTextVNode,
|
|
||||||
_m: i => legacyRenderStatic.bind(null, i),
|
_m: i => legacyRenderStatic.bind(null, i),
|
||||||
_g: () => legacyBindObjectListeners,
|
_f: () => resolveFilter,
|
||||||
|
_k: i => legacyCheckKeyCodes.bind(null, i),
|
||||||
|
_b: () => legacyBindObjectProps,
|
||||||
|
_v: () => createTextVNode,
|
||||||
|
_e: () => createCommentVNode,
|
||||||
_u: () => legacyresolveScopedSlots,
|
_u: () => legacyresolveScopedSlots,
|
||||||
_k: i => legacyCheckKeyCodes.bind(null, i)
|
_g: () => legacyBindObjectListeners,
|
||||||
|
_d: () => legacyBindDynamicKeys,
|
||||||
|
_p: () => legacyPrependModifier
|
||||||
} as PublicPropertiesMap)
|
} as PublicPropertiesMap)
|
||||||
}
|
}
|
||||||
|
@ -162,3 +162,21 @@ function isKeyNotMatch<T>(expect: T | T[], actual: T): boolean {
|
|||||||
return expect !== actual
|
return expect !== actual
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function legacyMarkOnce(tree: VNode) {
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
export function legacyBindDynamicKeys(props: any, values: any[]) {
|
||||||
|
for (let i = 0; i < values.length; i += 2) {
|
||||||
|
const key = values[i]
|
||||||
|
if (typeof key === 'string' && key) {
|
||||||
|
props[values[i]] = values[i + 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return props
|
||||||
|
}
|
||||||
|
|
||||||
|
export function legacyPrependModifier(value: any, symbol: string) {
|
||||||
|
return typeof value === 'string' ? symbol + value : value
|
||||||
|
}
|
||||||
|
@ -360,10 +360,11 @@ export type ExtractComputedReturns<T extends any> = {
|
|||||||
: T[key] extends (...args: any[]) => infer TReturn ? TReturn : never
|
: T[key] extends (...args: any[]) => infer TReturn ? TReturn : never
|
||||||
}
|
}
|
||||||
|
|
||||||
type WatchOptionItem =
|
export type ObjectWatchOptionItem = {
|
||||||
| string
|
handler: WatchCallback | string
|
||||||
| WatchCallback
|
} & WatchOptions
|
||||||
| { handler: WatchCallback | string } & WatchOptions
|
|
||||||
|
type WatchOptionItem = string | WatchCallback | ObjectWatchOptionItem
|
||||||
|
|
||||||
type ComponentWatchOptionItem = WatchOptionItem | WatchOptionItem[]
|
type ComponentWatchOptionItem = WatchOptionItem | WatchOptionItem[]
|
||||||
|
|
||||||
@ -949,7 +950,7 @@ function resolveData(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWatcher(
|
export function createWatcher(
|
||||||
raw: ComponentWatchOptionItem,
|
raw: ComponentWatchOptionItem,
|
||||||
ctx: Data,
|
ctx: Data,
|
||||||
publicThis: ComponentPublicInstance,
|
publicThis: ComponentPublicInstance,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user