zoukankan      html  css  js  c++  java
  • [Javascript] Manage Application State with Immutable.js

    Learn how Immutable.js data structures are different from native iterable Javascript data types and why they provide an excellent 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 you. The reference to them can change, but the data inside them cannot, which means you can build predictable and reliable state 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]); // todo1
    
    ary2[0] = "done1";
    console.log(ary[0]); // done1
    
    // Immutable 
    
    function updateState(immutable, pos, value) {
      return immutable.set(pos, value);
    }
    
    const immutableState = Immutable.List(["foo1", "foo2"]);
    const immutableState2 = immutableState.set(0, "bar1");
    
    console.log(immutableState.get(0)); // foo1
    console.log(immutableState2.get(0)); // bar1

    Every time you use set() to set a new value, Immutable will return a new array.

  • 相关阅读:
    Redis主从复制、哨兵Sentinel、集群简单介绍
    Redis集群
    Redis哨兵模式
    Redis主从架构
    Redis持久化方式
    缓存2.2——Redis并发竞争
    DOM内容梳理2
    纯js制作九宫格
    正则表达式内容梳理
    JavaScript之DOM详解
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4881252.html
Copyright © 2011-2022 走看看