fast-equals 5.1.3 → 5.2.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/index.cjs +15 -19
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +15 -19
- package/dist/esm/index.mjs.map +1 -1
- package/dist/min/index.js +1 -1
- package/dist/umd/index.js +15 -19
- package/dist/umd/index.js.map +1 -1
- package/index.d.ts +203 -21
- package/package.json +3 -2
- package/scripts/fallback-types.mjs +64 -0
- package/src/equals.ts +26 -32
package/src/equals.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type {
|
|
|
6
6
|
TypedArray,
|
|
7
7
|
} from './internalTypes';
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const PREACT_VNODE = '__v';
|
|
10
|
+
const PREACT_OWNER = '__o';
|
|
11
|
+
const REACT_OWNER = '_owner';
|
|
10
12
|
|
|
11
13
|
const { getOwnPropertyDescriptor, keys } = Object;
|
|
12
14
|
|
|
@@ -148,27 +150,12 @@ export function areObjectsEqual(
|
|
|
148
150
|
return false;
|
|
149
151
|
}
|
|
150
152
|
|
|
151
|
-
let property: string;
|
|
152
|
-
|
|
153
153
|
// Decrementing `while` showed faster results than either incrementing or
|
|
154
154
|
// decrementing `for` loop and than an incrementing `while` loop. Declarative
|
|
155
155
|
// methods like `some` / `every` were not used to avoid incurring the garbage
|
|
156
156
|
// cost of anonymous callbacks.
|
|
157
157
|
while (index-- > 0) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
property === OWNER &&
|
|
162
|
-
(a.$$typeof || b.$$typeof) &&
|
|
163
|
-
a.$$typeof !== b.$$typeof
|
|
164
|
-
) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
!hasOwn(b, property) ||
|
|
170
|
-
!state.equals(a[property], b[property], property, property, a, b, state)
|
|
171
|
-
) {
|
|
158
|
+
if (!isPropertyEqual(a, b, state, properties[index]!)) {
|
|
172
159
|
return false;
|
|
173
160
|
}
|
|
174
161
|
}
|
|
@@ -203,21 +190,7 @@ export function areObjectsEqualStrict(
|
|
|
203
190
|
while (index-- > 0) {
|
|
204
191
|
property = properties[index]!;
|
|
205
192
|
|
|
206
|
-
if (
|
|
207
|
-
property === OWNER &&
|
|
208
|
-
(a.$$typeof || b.$$typeof) &&
|
|
209
|
-
a.$$typeof !== b.$$typeof
|
|
210
|
-
) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (!hasOwn(b, property)) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
!state.equals(a[property], b[property], property, property, a, b, state)
|
|
220
|
-
) {
|
|
193
|
+
if (!isPropertyEqual(a, b, state, property)) {
|
|
221
194
|
return false;
|
|
222
195
|
}
|
|
223
196
|
|
|
@@ -355,3 +328,24 @@ export function areUrlsEqual(a: URL, b: URL): boolean {
|
|
|
355
328
|
a.password === b.password
|
|
356
329
|
);
|
|
357
330
|
}
|
|
331
|
+
|
|
332
|
+
function isPropertyEqual(
|
|
333
|
+
a: Dictionary,
|
|
334
|
+
b: Dictionary,
|
|
335
|
+
state: State<any>,
|
|
336
|
+
property: string | symbol,
|
|
337
|
+
) {
|
|
338
|
+
if (
|
|
339
|
+
(property === REACT_OWNER ||
|
|
340
|
+
property === PREACT_OWNER ||
|
|
341
|
+
property === PREACT_VNODE) &&
|
|
342
|
+
(a.$$typeof || b.$$typeof)
|
|
343
|
+
) {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
hasOwn(b, property) &&
|
|
349
|
+
state.equals(a[property], b[property], property, property, a, b, state)
|
|
350
|
+
);
|
|
351
|
+
}
|