Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TupleMap from '../index';
import Immutable from 'immutable';

describe('TupleMap', () => {
let cache;
Expand All @@ -13,8 +14,9 @@ describe('TupleMap', () => {

describe('#_hash', () => {
it('should create a hash for any number of args of any type', () => {
const tuple = [obj, arr, '123', 123, false];
const expectedHash = ['#0','#1','"123"','123','false'].join('/<[MI_SEP]>/');
const tuple = [obj, arr, '123', 123, false, Immutable.fromJS(obj)];
const immutableHash = '#' + Immutable.fromJS(obj).hashCode()
const expectedHash = ['#0','#1','"123"','123','false',immutableHash].join('/<[MI_SEP]>/');

expect(cache._hash( tuple )).toEqual( expectedHash );
expect(cache._lastTuple).toBe( tuple );
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ TupleMap.prototype = {
if ( this._idMap.has( arg ) ) {
hash.push( this._idMap.get(arg) );
} else {
const id = '#' + this._id++;
let id
if (typeof arg.hashCode === 'function') {
id = '#' + arg.hashCode();
} else {
id = '#' + this._id++;
}
this._idMap.set( arg, id );
hash.push( id );
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"babel-preset-es2015": "^6.18.0",
"coveralls": "^2.11.15",
"eslint": "^3.12.2",
"immutable": "^3.8.1",
"jest": "^17.0.3",
"rimraf": "^2.5.4"
}
Expand Down