Skip to content

Commit

Permalink
Contains fix for error during equals check on Record with undefined o…
Browse files Browse the repository at this point in the history
…r null
  • Loading branch information
anilreddykatta committed Jun 9, 2017
1 parent c0308e7 commit 7554820
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions __tests__/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ describe('Record', () => {
expect(t1.equals(t2));
});

it('if compared against undefined or null should return false', () => {
const MyType = Record({ a: 1, b: 2 });
const t1 = new MyType();
expect(t1.equals(undefined)).toBeFalsy();
expect(t1.equals(null)).toBeFalsy();
});

it('merges in Objects and other Records', () => {
let Point2 = Record({x: 0, y: 0});
let Point3 = Record({x: 0, y: 0, z: 0});
Expand Down
4 changes: 3 additions & 1 deletion dist/immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5236,7 +5236,9 @@ Record.prototype.toString = function toString () {

Record.prototype.equals = function equals (other) {
return this === other ||
(this._keys === other._keys && recordSeq(this).equals(recordSeq(other)));
(other &&
this._keys === other._keys &&
recordSeq(this).equals(recordSeq(other)));
};

Record.prototype.hashCode = function hashCode () {
Expand Down
4 changes: 2 additions & 2 deletions dist/immutable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export class Record {

equals(other) {
return this === other ||
(this._keys === other._keys && recordSeq(this).equals(recordSeq(other)));
(other &&
this._keys === other._keys &&
recordSeq(this).equals(recordSeq(other)));
}

hashCode() {
Expand Down

0 comments on commit 7554820

Please sign in to comment.