为什么 2 immutable.js 列表差异很大?
Why 2 immutable.js Lists is deeply different?
我无法使用简单的深度对象比较来深入比较 2 个列表。
考虑以下代码:
import {fromJS} from 'immutable';
import {describe, it} from 'mocha';
import { expect } from 'chai';
const o = {a: 123};
const A = fromJS([o]);
const B = fromJS([]).push(fromJS(o));
describe('Check', () => {
it('should be deep equal', () => {
expect(A).to.deep.equal(B);
});
});
为什么 Immutable.js 集合实际上有状态?
我看到了像 chai-immutable 这样的库,但我想了解这种行为的目的?
Immutable.js 使用状态来提高效率,因此当您将某些内容添加到不可变列表时,引用会有所不同,但它实际上不会复制所有内容并且是 O(n)。
如他们所说 Github :
These data structures are highly efficient on modern JavaScript VMs by using structural sharing via hash maps tries and vector tries as popularized by Clojure and Scala, minimizing the need to copy or cache data.
我无法使用简单的深度对象比较来深入比较 2 个列表。
考虑以下代码:
import {fromJS} from 'immutable';
import {describe, it} from 'mocha';
import { expect } from 'chai';
const o = {a: 123};
const A = fromJS([o]);
const B = fromJS([]).push(fromJS(o));
describe('Check', () => {
it('should be deep equal', () => {
expect(A).to.deep.equal(B);
});
});
为什么 Immutable.js 集合实际上有状态?
我看到了像 chai-immutable 这样的库,但我想了解这种行为的目的?
Immutable.js 使用状态来提高效率,因此当您将某些内容添加到不可变列表时,引用会有所不同,但它实际上不会复制所有内容并且是 O(n)。
如他们所说 Github :
These data structures are highly efficient on modern JavaScript VMs by using structural sharing via hash maps tries and vector tries as popularized by Clojure and Scala, minimizing the need to copy or cache data.