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. linux服务器加入windows域时报错Ticket expired

    [root@rusky]# net ads join -U administrator Enter administrator's password: kinit succeeded but ads_ ...

  2. sql server数据库将excel表中的数据导入数据表

    一般有两种方法可以实现,一种是直接写sql语句,另外一种是利用sqlserver的管理工具实现.这里介绍的是后面一种方法. 步骤: 一.准备数据 1.将excel表另存为文本格式,注意文本格式需为ta ...

  3. 为什么要用Math.sqrt(i)方法

    java 练习题 判断 101-200 之间有多少个素数,并输出所有素数 public class Prime { public static int count = 0; public static ...

  4. $.fn、$.fn.extend和$.extend的区别

    $.fn $.fn是指jquery的命名空间,加在fn上的方法及属性,会对jquery实例每一个有效. 如:扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法,那么后 ...

  5. OpenGL ES 2.0 绘制方式

    OpenGL ES 中支持的绘制方式大致分3类,包括点.线段.三角形,每类中包括一种或多种具体的绘制方式. GL_POINTS 传入渲染管线的一系列顶点单独进行绘制. GL_LINES   传入渲染管 ...

  6. hdu4296 贪心

    E - 贪心 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit I ...

  7. MFC中函数名前加 :: 原因

    在开发MFC之前,开发的是以AFx(Application Frameworks,x是没有什么意义的)开头的一些函数.但是那个时候开发的函数并没有进行封装,但是有很多很有用的函数.最后AFx开发失败, ...

  8. hadoop容灾能力测试

    实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...

  9. 【JAVA编码专题】总结

    第一部分:编码基础 为什么需要编码:用计算机看得懂的语言(二进制数)表示各种各样的字符. 一.基本概念 ASCII.Unicode.big5.GBK等为字符集,它们只定义了这个字符集内有哪些字符,以及 ...

  10. Ajax调用asp.net后台代码

    后台代码: [WebMethod] public static string CreateDate(string name,string age) { return "姓名:"+n ...