types(runtime-core): refactor defineComponent (#1883)
This commit is contained in:
@@ -32,17 +32,17 @@ const readonlyGet = /*#__PURE__*/ createGetter(true)
|
||||
const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true)
|
||||
|
||||
const arrayInstrumentations: Record<string, Function> = {}
|
||||
;['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
|
||||
arrayInstrumentations[key] = function(...args: any[]): any {
|
||||
const arr = toRaw(this) as any
|
||||
for (let i = 0, l = (this as any).length; i < l; i++) {
|
||||
;(['includes', 'indexOf', 'lastIndexOf'] as const).forEach(key => {
|
||||
arrayInstrumentations[key] = function(this: unknown[], ...args: unknown[]) {
|
||||
const arr = toRaw(this)
|
||||
for (let i = 0, l = this.length; i < l; i++) {
|
||||
track(arr, TrackOpTypes.GET, i + '')
|
||||
}
|
||||
// we run the method using the original args first (which may be reactive)
|
||||
const res = arr[key](...args)
|
||||
const res = (arr[key] as any)(...args)
|
||||
if (res === -1 || res === false) {
|
||||
// if that didn't work, run it again using raw values.
|
||||
return arr[key](...args.map(toRaw))
|
||||
return (arr[key] as any)(...args.map(toRaw))
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user