Learn how to create an immutable.map () through plain Javascript object construction and also via array tuples.
console.clear (); // Can is an object var map = Immutable.map ({key: "value"}); Console.log (Map.get (//"value"// Can is an arrayvar map = Immutable.map ([["Key", {"name": "Zhentian"}]]); Console.log ( Map.get (//"Zhentian"// size prop//1
Mocha.setup (' BDD '); const expect=Chai.expect;functionCreateobjtodos (numtodos) {varobj ={} _.each (_.range (Numtodos), (index)={Const Todosequence= String (index+1); obj[' Todo ' +todosequence] ={title:' Todo ' +todosequence, Value: ' Make ${todosequence} happen '}; }); returnobj; } Describe (' Creating an immutable Object Graph with Immutable.js Map () ', () = ={It (' should create MAP () with matching Keys ', () ={Const data= { "Todo1": {title:"Todo 1", Value:"Make It Happen" }, "Todo2": {title:"Todo 2", Value:"Make It Happen"}} Let map=immutable.map (data); Expect (Map.get ("Todo1"). Title). To.equal ("Todo 1"); }); It (' should create MAP () with keys from array tuples ', () ={Let map= Immutable.map ([["Todo1", {title: "Todo 1"}])//Note the array within arrayExpect (Map.get ("Todo1"). Title). To.equal ("Todo 1"); }); It (' should create MAP () with matching size to number of keys ', () ={Let map= Immutable.map (Createobjtodos (3) ) expect (map.size). To.equal (3); }); }); Mocha.run ();
[Javascript] Creating an immutable Object Graph with Immutable.js Map ()