Skip to content

Commit 84dc76f

Browse files
authored
Chore: Optimizations (#57)
* Some micro-ops index.js * Update modification notes * Get rid of strict * Update numbers * Update changelog * ignore VS Code config Co-authored-by: Chris Bolin, Phil Plückthun
1 parent 09c5266 commit 84dc76f

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rules:
1919
no-eq-null: 2
2020
no-fallthrough: 2
2121
no-return-assign: 2
22-
strict: [ 2, global ]
22+
strict: 0
2323
no-use-before-define: [ 2, nofunc ]
2424
callback-return: 2
2525
no-path-concat: 2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ package-lock.json
6060
# dotenv environment variables file
6161
.env
6262

63+
# editors
64+
.vscode/
65+
6366
.DS_Store

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## 3.0.0 (2020-01-31)
44

55
**Features:**
6-
76
- [#36](https://github.com/FormidableLabs/react-fast-compare/pull/36). Update to `fast-deep-equal@3.1.1` with modified support for ES.next data types: `Map`, `Set`, `ArrayBuffer`.
7+
- [#57](https://github.com/FormidableLabs/react-fast-compare/pull/57). Minor refactoring to reduce min+gz size.
88

99
**Breaking changes:**
1010

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ $ yarn -s compress
104104

105105
# Display minified + gzip'ed size in bytes.
106106
$ yarn size-min-gz
107-
687
108107
```
109108

110109
**Note**: If the min+gz size increases, please note it in the README. If it is a significant increase, please flag to your reviewers and have a discussion about whether or not the size addition is justified.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $ npm install react-fast-compare
3333
- handles React-specific circular references, like elements
3434
- checks equality Date and RegExp objects
3535
- should as fast as [fast-deep-equal](https://github.com/epoberezkin/fast-deep-equal) via a single unified library, and with added guardrails for circular references.
36-
- small: under 700 bytes minified+gzipped
36+
- small: under 650 bytes minified+gzipped
3737

3838
## Usage
3939

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21
/* global Map:readonly, Set:readonly, ArrayBuffer:readonly */
32

43
var hasElementType = typeof Element !== 'undefined';
@@ -39,7 +38,7 @@ function equal(a, b) {
3938
//
4039
// ```js
4140
// it = a.entries();
42-
// for (i = it.next(); !i.done; i = it.next())
41+
// while (!(i = it.next()).done)
4342
// if (!b.has(i.value[0])) return false;
4443
// ```
4544
//
@@ -48,18 +47,18 @@ function equal(a, b) {
4847
if (hasMap && (a instanceof Map) && (b instanceof Map)) {
4948
if (a.size !== b.size) return false;
5049
it = a.entries();
51-
for (i = it.next(); !i.done; i = it.next())
50+
while (!(i = it.next()).done)
5251
if (!b.has(i.value[0])) return false;
5352
it = a.entries();
54-
for (i = it.next(); !i.done; i = it.next())
53+
while (!(i = it.next()).done)
5554
if (!equal(i.value[1], b.get(i.value[0]))) return false;
5655
return true;
5756
}
5857

5958
if (hasSet && (a instanceof Set) && (b instanceof Set)) {
6059
if (a.size !== b.size) return false;
6160
it = a.entries();
62-
for (i = it.next(); !i.done; i = it.next())
61+
while (!(i = it.next()).done)
6362
if (!b.has(i.value[0])) return false;
6463
return true;
6564
}
@@ -91,8 +90,7 @@ function equal(a, b) {
9190

9291
// custom handling for React
9392
for (i = length; i-- !== 0;) {
94-
var key = keys[i];
95-
if (key === '_owner' && a.$$typeof) {
93+
if (keys[i] === '_owner' && a.$$typeof) {
9694
// React-specific: avoid traversing React elements' _owner.
9795
// _owner contains circular references
9896
// and is not needed when comparing the actual elements (and not their owners)
@@ -101,7 +99,7 @@ function equal(a, b) {
10199
}
102100

103101
// all other properties should be traversed as usual
104-
if (!equal(a[key], b[key])) return false;
102+
if (!equal(a[keys[i]], b[keys[i]])) return false;
105103
}
106104
// END: react-fast-compare
107105

@@ -117,13 +115,13 @@ module.exports = function exportedEqual(a, b) {
117115
try {
118116
return equal(a, b);
119117
} catch (error) {
120-
if (((error.message || '').match(/stack|recursion/i)) || (error.number === -2146828260)) {
118+
if (((error.message || '').match(/stack|recursion/i))) {
121119
// warn on circular references, don't crash
122120
// browsers give this different errors name and messages:
123121
// chrome/safari: "RangeError", "Maximum call stack size exceeded"
124122
// firefox: "InternalError", too much recursion"
125123
// edge: "Error", "Out of stack space"
126-
console.warn('Warning: react-fast-compare does not handle circular references.', error.name, error.message);
124+
console.warn('react-fast-compare cannot handle circular refs');
127125
return false;
128126
}
129127
// some other error. we should definitely know about these

0 commit comments

Comments
 (0)