[Javascript] Creating an immutable Object Graph with Immutable.js Map ()

Source: Internet
Author: User

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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.