Skip to content

Commit

Permalink
chore(watch): use polyfill instead of object.is (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Feb 7, 2022
1 parent b71e690 commit 4a4ed5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/apis/watch.ts
Expand Up @@ -11,6 +11,7 @@ import {
isPlainObject,
isSet,
isMap,
isSame,
} from '../utils'
import { defineComponentInstance } from '../utils/helper'
import { getVueConstructor } from '../runtimeContext'
Expand Down Expand Up @@ -346,7 +347,7 @@ function createWatcher(
if (
!deep &&
isMultiSource &&
n.every((v: any, i: number) => Object.is(v, o[i]))
n.every((v: any, i: number) => isSame(v, o[i]))
)
return
// cleanup before running cb again
Expand Down
12 changes: 12 additions & 0 deletions src/utils/utils.ts
Expand Up @@ -112,3 +112,15 @@ export function logError(err: Error, vm: Vue, info: string) {
throw err
}
}

/**
* Object.is polyfill
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
* */
export function isSame(value1: any, value2: any): boolean {
if (value1 === value2) {
return value1 !== 0 || 1 / value1 === 1 / value2
} else {
return value1 !== value1 && value2 !== value2
}
}

0 comments on commit 4a4ed5d

Please sign in to comment.