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. Hadoop Failed to set permissions of path

    在Eclipse里面写了个測试程序:把HDFS中的数据批量导入到HBase中 写好后,在本地測试遇到了例如以下问题: 14/04/21 16:49:53 WARN util.NativeCodeLoa ...

  2. 什么是 gnuplot

    Gnuplot是一个命令行的交互式绘图工具(command-driven interactive function plotting program).用户通过输入命令,可以逐步设置或修改绘图环境,并 ...

  3. gulp入门学习实例

    好久都没有更新博客了,每天繁忙的工作,下班之后都不想开设备了.前段时间有幸学习了一下gulp这款构建工具,现在和大家分享一下. 为什么使用Gulp Gulp基于Node.js的前端构建工具,通过Gul ...

  4. WebApi2官网学习记录---Attribute Routing

    从WebApi 1迁移到WebAPI 2要改变配置代码如下: WebApi 1: protected void Application_Start() { // WARNING - Not compa ...

  5. SQL Server 创建链接服务器

    遇到下列问题: 线上服务器A,中转服务器B,本地服务器C 数据在A上面,想在B上面操作类似 select * from [A].[database].table这样的SQL,不用去链接服务器,直接把处 ...

  6. http 压缩

    HTTP压缩是在Web服务器 和浏览器间传输压缩文本内容的方法.HTTP压缩采用通用的压缩算法如gzip等压缩HTML.JavaScript或 CSS文件.压缩的最大好处就是降低了网络传输的数据量,从 ...

  7. Windows命令行(DOS命令)教程-5 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_4.html

    5. copy copy在英文中是复制的意思 [功能] 复制一个或一组文件到指定的磁盘或目录中 [格式] copy [C:][path][filename.ext] [C:][path]filenam ...

  8. js中的for-of循环遍历数组

    遍历数组要怎么做,可能你首先想到的会是for循环,当然for循环在JavaScript 刚萌生的时候就出现了,想到它也是理所当然的 var a=[[1,2],[3,4],5] for(var i=0; ...

  9. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

  10. Maven基础教程

    更多内容请参考官方文档:http://maven.apache.org/guides/index.html 官方文档很详细,基本上可以查找到一切相关的内容. 另外,快速入门可参考视频:孔浩的maven ...