Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ReactJS Boston: Values and Equality in Immutable.js

ReactJS Boston: Values and Equality in Immutable.js

Exploring the what and how of equality of Immutable collections in JavaScript.

Presented on May 25th, 2016 at the ReactJS Boston Meetup.
http://www.meetup.com/ReactJS-Boston/events/230994535/

Colby Rabideau

May 25, 2016
Tweet

Other Decks in Technology

Transcript

  1. (1 + 1) === 2 (3 - 1) === 2

    (2 * 1) === 2 (2 / 1) === 2 Numbers can express new numbers immutably
  2. Numbers Arrays Lists Portable ✔ ✔ ✔ Generic ✔ ✔

    ✔ Immutable ✔ ✔ Types of equality
  3. for (i = 0; i < size; i++) { if

    (!is(a[i], b[i])) { return false; } } return true;
  4. const memoize = (op) => { let cache = Map();

    return (key) => { if (!cache.has(key)) { cache = cache.set(key, op(key));
 } return cache.get(key); }; }
  5. const memoFetch = memoize(fetch) // does work const apiPromise =

    memoFetch(Map({ id: 5678, page: 4, })); // cached result memoFetch(Map({ id: 5678, page: 4, })) === apiPromise