Skip to content

Commit 7d0a9ab

Browse files
committed
perf(wx-react): optimize objectIs
1 parent 4ddb7cf commit 7d0a9ab

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/wx-react/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"scripts": {
1111
"test": "echo \"Error: no test specified\" && exit 1",
1212
"build": "rollup -c",
13-
"pub-beta": "npm publish --tag=beta",
14-
"pub": "npm publish"
13+
"pub-beta": "npm run build && npm publish --tag=beta",
14+
"pub": "npm run build && npm publish"
1515
},
1616
"author": "",
1717
"license": "MIT"

packages/wx-react/src/shallowEqual.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88

99
const hasOwn = Object.prototype.hasOwnProperty
1010

11-
function is(x, y) {
12-
if (x === y) {
13-
return x !== 0 || y !== 0 || 1 / x === 1 / y
14-
} else {
15-
return x !== x && y !== y
11+
// 参考:https://github.com/facebook/react/pull/16212
12+
let is
13+
if (typeof Object.is === 'function') {
14+
is = Object.is
15+
} else {
16+
is = (x, y) => {
17+
if (x === y) {
18+
return x !== 0 || y !== 0 || 1 / x === 1 / y
19+
} else {
20+
return x !== x && y !== y
21+
}
1622
}
1723
}
1824

25+
26+
1927
export default function shallowEqual(objA, objB) {
2028
if (is(objA, objB)) return true
2129

0 commit comments

Comments
 (0)