[Javascript] Manage application state with Immutable.js

Source: Internet
Author: User

Learn how immutable.js data structures is different from native iterable Javascript data types and why they provide an ex Cellent Foundation on which to build your application ' s state.

Instead of them being mutable, they ' re always immutable, meaning they don ' t change from underneath. The reference to them can change, but the data inside them cannot, which means you can build predictable and reliable stat E models on top of them. It becomes a lot easier to manage your application ' s state.

console.clear (); const ARY= ["Todo1", "Todo2"];const Ary2=Ary;console.log (ary[0]);//Todo1ary2[0] = "done1"; Console.log (ary[0]);//done1//Immutablefunctionupdatestate (immutable, POS, value) {returnImmutable.set (pos, value);} Const Immutablestate= Immutable.list (["Foo1", "Foo2"]); Const IMMUTABLESTATE2= Immutablestate.set (0, "bar1"); Console.log (Immutablestate.get (0));//foo1Console.log (immutablestate2.get (0));//bar1

Every time you use Set () to set a new value, immutable would return a new array.

[Javascript] Manage application state with Immutable.js

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.