Skip to content

Commit

Permalink
extract helper function and check for null prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD committed Aug 27, 2024
1 parent 1b8aba8 commit ea9bf3b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/vuetify/src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export function isObject (obj: any): obj is Record<string, any> {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj)
}

export function isPlainObject (obj: any): obj is Record<string, any> {
let proto
return obj !== null && typeof obj === 'object' && (
(proto = Object.getPrototypeOf(obj)) === Object.prototype ||
proto === null
)
}

export function refElement (obj?: ComponentPublicInstance<any> | HTMLElement): HTMLElement | undefined {
if (obj && '$el' in obj) {
const el = obj.$el as HTMLElement
Expand Down Expand Up @@ -488,16 +496,13 @@ export function mergeDeep (

// Only continue deep merging if
// both properties are plain objects
if (
isObject(sourceProperty) && Object.getPrototypeOf(sourceProperty) === Object.prototype &&
isObject(targetProperty) && Object.getPrototypeOf(targetProperty) === Object.prototype
) {
if (isPlainObject(sourceProperty) && isPlainObject(targetProperty)) {
out[key] = mergeDeep(sourceProperty, targetProperty, arrayFn)

continue
}

if (Array.isArray(sourceProperty) && Array.isArray(targetProperty) && arrayFn) {
if (arrayFn && Array.isArray(sourceProperty) && Array.isArray(targetProperty)) {
out[key] = arrayFn(sourceProperty, targetProperty)

continue
Expand Down

0 comments on commit ea9bf3b

Please # to comment.