-
ImmuTable
2021-01-08 04:51:15<p>ImmuTable was already introduced in #4510 but I'm extracting it to a separate PR for easier review. <p>If you want to test it and see it in action, I've reimplemented Settings with ... -
immutable
2020-03-29 00:32:431、immutable介绍:immutable对象是不可直接赋值的对象,它可以有效的避免错误赋值的问题 2、安装 npm install immutable 3、immutable的使用方法 创建一个immutable对象并修改 const {Map} = require('immutable')...1、immutable介绍:immutable对象是不可直接赋值的对象,它可以有效的避免错误赋值的问题
2、安装npm install immutable
3、immutable的使用方法
创建一个immutable对象并修改const {Map} = require('immutable') let preState = { //创建一个普通对象 name : "sultan", age : 22 } let map1 = Map(preState) //使用Map方法将普通对象转换成一个immutable对象 let map2 = map1.set("name","xiaoming") //使用set方法修改immutable对象的属性 console.log(map1.toJS(),map2.toJS()) //toJS方法用来将immutable对象转成普通js对象 //结果为{ name: 'sultan', age: 22 } { name: 'xiaoming', age: 22 } 说明immutable对象调用Map.set方法适合,不会改变原来的对象,只会生成一个新的对象,并且修改新对象。
创建并修改一个immutable数组
const {List} = require('immutable') let prestate = [1,2,3,4,5] let arr1 = List(prestate) let arr2 = arr1.splice(1,1,666) console.log(arr1.toJS(),arr2.toJS()) //结果为[ 1, 2, 3, 4, 5 ] [ 1, 666, 3, 4, 5 ] 即使用了splice方法,还是不会影响之前的数组。
合并两个immutable对象
const {Map} = require('immutable') var prestate = { a : 1 } var obj = { b : 1 } var map1 = Map(prestate) var map2 = map1.merge(obj) console.log(map1.toJS(),map2.toJS()) //结果为{ a: 1 } { a: 1, b: 1 } 可以进行对象合并
合并immutable数组
const {List} = require('immutable') let arr1 = [1,2,3] let arr2 = [4,5,6] let arr3 = List(arr1) let arr4 = arr3.concat(arr2) console.log(arr4.toJS()) //结果为[ 1, 2, 3, 4, 5, 6 ] concat用于进行数组的合并
将一个复杂的具有嵌套结构的immutable对象进行修改
const {fromJS} = require('immutable') var obj = { name : "sultan", age : 100, localtion : { city : "shanxi", a : { b:1 } }, list : [1,2,3] } var obj2 = fromJS(obj) //讲一个复杂的嵌套结构的对象转换成immutable对象 var obj3 = obj2.setIn(["localtion","city"],"dalian") var obj4 = obj2.updateIn(["list"],data => data.splice(1,1,555)) console.log(obj3.toJS(),obj4.toJS())
-
Immutable
2020-03-31 09:56:05Immutable https://www.jianshu.com/p/0fa8c7456c15 不可变数据:**Immutable Data 就是一旦创建,就不能再被更改的数据。对Immutable对象的任何修改、添加、删除操作都会返回一个新的Immutable对象。Immutable实现...Immutable
https://www.jianshu.com/p/0fa8c7456c15
不可变数据:**Immutable Data 就是一旦创建,就不能再被更改的数据。对Immutable对象的任何修改、添加、删除操作都会返回一个新的Immutable对象。Immutable实现原理是Persistent Data Structure(持久化数据结构),也就是使用旧数据创建新数据时,要保证旧数据同时可用且不可变。同时为了避免DeepCopy把所有节点都复制一遍带来的性能损耗,Immutable使用了Structural Sharing(结构共享),即如果对象树中一个节点发生变化,只修改这个节点和受它影响的父节点,其它节点则进行共享。在React中使用:熟悉 React 的都知道,React 做性能优化时有一个避免重复渲染的大招,就是使用 shouldComponentUpdate(),但它默认返回 true,即始终会执行 render() 方法,然后做 Virtual DOM 比较,并得出是否需要做真实 DOM 更新,这里往往会带来很多无必要的渲染并成为性能瓶颈。
当然我们也可以在 shouldComponentUpdate() 中使用使用 deepCopy 和 deepCompare 来避免无必要的 render(),但 deepCopy 和 deepCompare 一般都是非常耗性能的。
Immutable 则提供了简洁高效的判断数据是否变化的方法,只需 === 和 is 比较就能知道是否需要执行 render(),而这个操作几乎 0 成本,所以可以极大提高性能。
-
Mastering Immutable
2018-03-27 13:35:21Mastering Immutable PDF Mastering Immutable epub Mastering Immutable azw3 示例源码 -
Immutable collections for JavaScript Immutable data cannot be changed once created, leading to much simpler application development, no defensive copying, and enabling advanced memoization and ...
-
Immutable classes with immutable fields should use immutable implementation
2021-01-07 11:18:31If the implementation of B is mutable, then the immutable version of A is therefore also, unfortunately, mutable. Another side-effect is <code>a.getB()</code> does not have the niceties like <code>... -
Immutable list is not really immutable
2021-01-03 14:33:06Immutable<string> immutable = new Immutable<>(new ArrayList<>(Arrays.asList("a", "b", "c"))); int originalSize = immutable.size(); immutable.... -
Immutable actuals
2020-12-09 02:40:35s because <code>Immutable.is</code> is only used when the "actual" value is an Immutable collection. This fixes it.</p><p>该提问来源于开源项目:astorije/chai-immutable</p></div>