While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of referencing each key and value in both objects. For lightning fast equality checks, Immutable.js can produce a hash code based on an iterable's content. If two iterables have the same content, their hash codes will be the same. It's worth noting that this technique is unsuitable for mission critical application development since there is a chance, however slight, that checksums like these might collide. This is outlined here: https://en.wikipedia.org/wiki/Collision_(computer_science)

mocha.setup('bdd');
const expect = chai.expect; class Todo { constructor(title="", items=Immutable.List(), completed=false) {
this.id = (+new Date() + Math.floor(Math.random() * 999999)).toString(36);
this.title = title;
this.items = items;
this.completed = completed;
} } function generateTodos() { const todos = [] _.each(_.range(5), index => {
var todo = new Todo(`Todo ${index}`); todo.completed = Math.round(Math.random()) === 0; _.each(_.range(Math.floor(Math.random()*100)), index => {
todo.items = todo.items.push(`Item ${index}`);
}); todos.push(todo); }); return todos;
} describe('Lightning Fast Equality checks with Hash Codes', () => { it('should take separate lists with the same items and see equal hash codes', () => { var todos = generateTodos(); let todos1 = Immutable.List.of(...todos);
let todos2 = Immutable.List.of(...todos); expect(todos1).to.not.equal(todos2);
expect(todos1.hashCode()).to.equal(todos2.hashCode()); }); }); mocha.run();

[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes的更多相关文章

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

    Learn how to create an Immutable.Map() through plain Javascript object construction and also via arr ...

  2. Node.js学习笔记——Node.js开发Web后台服务

    一.简介 Node.js 是一个基于Google Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效.Node.j ...

  3. Node.js系列之node.js初探

    官方介绍:Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable n ...

  4. H5案例分享:JS手势框架 —— Hammer.js

    JS手势框架 -- Hammer.js 一.hammer.js简介 hammerJS是一个开源的,轻量级的触屏设备javascript手势库,它可以在不需要依赖其他东西的情况下识别触摸,鼠标事件.允许 ...

  5. Js的typeof和Js的基本数据类型

    本文将从以下几个方面介绍Js的typeof和Js的基本数据类型: ** Js的typeof的用法 ** Js的基本数据类型 ** 使用基本类型使用typeof的返回结果 ** Js的typeof的用法 ...

  6. js get browser vertion (js获取浏览器信息版本)

    1问题:js get browser vertion (js获取浏览器信息版本) 2解决方案 Copy this script into your JavaScript files. It works ...

  7. 1-7 basket.js localstorage.js缓存css、js

    basket.js 源码分析   api 使用文档: http://t3n.de/news/basketjs-performance-localstorage-515119/       一.前言 b ...

  8. 【js跨域】js实现跨域访问的几种方式

    这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协议.域名.端口有任何一个不同,都被 ...

  9. Node.js入门:Node.js&NPM的安装与配置

    Node.js安装与配置      Node.js已经诞生两年有余,由于一直处于快速开发中,过去的一些安装配置介绍多数针对0.4.x版本而言的,并非适合最新的0.6.x的版本情况了,对此,我们将在0. ...

随机推荐

  1. [RxJS] Reactive Programming - Clear data while loading with RxJS startWith()

    In currently implemention, there is one problem, when the page load and click refresh button, the us ...

  2. springmvc4+hibernate4分页查询功能

    Springmvc+hibernate成为现在很多人用的框架整合,最近自己也在学习摸索,由于我们在开发项目中很多项目都用到列表分页功能,在此参考网上一些资料,以springmvc4+hibnerate ...

  3. 无法从带有索引像素格式的图像创建graphics对象(转)

    大家在用 .NET 做图片水印功能的时候, 很可能会遇到 “无法从带有索引像素格式的图像创建graphics对象”这个错误,对应的英文错误提示是“A Graphics object cannot be ...

  4. MySql安装与卸载

    win2003下MySql的配置 准备相关组件 1.MySql安装包 mysql-installer-commercial- 5.6.14.0.msi 2.Microsoft .NETFramewor ...

  5. 4 常量类--Map常量

    public static final HashMap<String, String> ETL_SOURCE_INPUTTYPE_MAP = new HashMap<String, ...

  6. C#数组的指定位置复制函数

    1. // 源数组 - 起始位置 -目的数组 - 起始位置 - 长度 System.Array.Copy(mcu_data, 2, read_mcu_data_whole, 0, mcu_data.L ...

  7. 最小日志量的insert操作

    --1.实验环境 SQL> conn scott/tiger Connected to Oracle Database 11g Enterprise Edition Release 11.2.0 ...

  8. java基础知识再学习--HashMap与ConcurrentHashMap的区别

    引用:http://blog.csdn.net/xuefeng0707/article/details/40834595 从JDK1.2起,就有了HashMap,正如前一篇文章所说,HashMap不是 ...

  9. centos中的配置文件

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...

  10. jquery中checkbox全选失效的解决方法

    这篇文章主要介绍了jquery中checkbox全选失效的解决方法,需要的朋友可以参考下     如果你使用jQuery 1.6 ,代码if ( $(elem).attr(“checked”) ),将 ...