Skip to content

Commit

Permalink
fix(ObjectUtils): only check for hashCode on truthy objects (#76)
Browse files Browse the repository at this point in the history
fix(ObjectUtils): only check for hashCode on truthy objects
  • Loading branch information
aem authored Nov 25, 2019
2 parents 9230196 + 2eb80da commit a343597
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.2.1
* Fix shallowCompare function when one or both inputs is falsy.

## 3.2.0
* Fix potential infinite loop with Immutable dependency values (#74)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "general-store",
"version": "3.2.0",
"version": "3.2.1",
"description": "Simple, flexible store implementation for Flux.",
"main": "lib/GeneralStore.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/ObjectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function shallowEqual(obj1: any, obj2: any): Boolean {
// While this technically means this is deep equality for Immutables,
// it's better to have a more specific check than an entirely incorrect one.
if (
obj1 &&
obj2 &&
typeof obj1.hashCode === 'function' &&
typeof obj2.hashCode === 'function'
) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/__tests__/ObjectUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,9 @@ describe('ObjectUtils', () => {
// force hash collision - should fall back to .equals
expect(shallowEqual(mockImmutable1, mockImmutable2)).toBe(false);
});

it('handles immutable values if one input is falsy', () => {
expect(() => shallowEqual(Map({ a: 1 }), null)).not.toThrow();
});
});
});

0 comments on commit a343597

Please sign in to comment.