wip(compiler-ssr): v-model static types + textarea
This commit is contained in:
@@ -9,6 +9,7 @@ export * from './normalizeProp'
|
||||
export * from './domTagConfig'
|
||||
export * from './domAttrConfig'
|
||||
export * from './escapeHtml'
|
||||
export * from './looseEqual'
|
||||
|
||||
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
|
||||
? Object.freeze({})
|
||||
|
||||
42
packages/shared/src/looseEqual.ts
Normal file
42
packages/shared/src/looseEqual.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { isObject, isArray } from './'
|
||||
|
||||
export function looseEqual(a: any, b: any): boolean {
|
||||
if (a === b) return true
|
||||
const isObjectA = isObject(a)
|
||||
const isObjectB = isObject(b)
|
||||
if (isObjectA && isObjectB) {
|
||||
try {
|
||||
const isArrayA = isArray(a)
|
||||
const isArrayB = isArray(b)
|
||||
if (isArrayA && isArrayB) {
|
||||
return (
|
||||
a.length === b.length &&
|
||||
a.every((e: any, i: any) => looseEqual(e, b[i]))
|
||||
)
|
||||
} else if (a instanceof Date && b instanceof Date) {
|
||||
return a.getTime() === b.getTime()
|
||||
} else if (!isArrayA && !isArrayB) {
|
||||
const keysA = Object.keys(a)
|
||||
const keysB = Object.keys(b)
|
||||
return (
|
||||
keysA.length === keysB.length &&
|
||||
keysA.every(key => looseEqual(a[key], b[key]))
|
||||
)
|
||||
} else {
|
||||
/* istanbul ignore next */
|
||||
return false
|
||||
}
|
||||
} catch (e) {
|
||||
/* istanbul ignore next */
|
||||
return false
|
||||
}
|
||||
} else if (!isObjectA && !isObjectB) {
|
||||
return String(a) === String(b)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function looseIndexOf(arr: any[], val: any): number {
|
||||
return arr.findIndex(item => looseEqual(item, val))
|
||||
}
|
||||
Reference in New Issue
Block a user