While Immutable.js offers. was () to confirm value equality between iterables it comes at the cost of referencing each key a nd value in both objects. For lightning fast equality checks, immutable.js can produce a hash code based on a iterable ' s content. If the iterables has the same content, the their hash codes would be the same. It's worth noting that this technique was unsuitable for mission critical application development since there are a chance, However slight, that's checksums like these might collide. This is outlined Here:https://en.wikipedia.org/wiki/collision_ (computer_science)
Mocha.setup (' BDD '); const expect=Chai.expect;class Todo {constructor (title= "", Items=immutable.list (), completed=false) { This. ID = (+NewDate () + Math.floor (math.random () * 999999)). ToString (36); This. title =title; This. Items =items; This. completed =completed; } }functionGeneratetodos () {const Todos=[] _.each (_.range (5), index = { varTodo =Newtodo (' Todo ${index} '); Todo.completed= Math.Round (Math.random ()) = = = 0; _.each (_.range (Math.floor (Math.random ()*100)), index ={Todo.items=Todo.items.push (' Item ${index} '); }); Todos.push (TODO); }); returnTodos;} Describe (' Lightning Fast equality checks with Hash Codes ', () ={It (' should take separate lists with the same items and see equal hash Codes ', () = { varTodos =Generatetodos (); Let Todos1=Immutable.List.of (... todos); Let Todos2=Immutable.List.of (... todos); Expect (TODOS1). To.not.equal (TODOS2); Expect (Todos1.hashcode ()). To.equal (Todos2.hashcode ()); }); }); Mocha.run ();
[Immutable.js] Lightning Fast immutable.js equality Checks with Hash Codes