Skip to content

Instantly share code, notes, and snippets.

@a-x-
Created October 27, 2017 22:40
Show Gist options
  • Save a-x-/63f84a5e726cc00c644f0cdfe8ab929f to your computer and use it in GitHub Desktop.
Save a-x-/63f84a5e726cc00c644f0cdfe8ab929f to your computer and use it in GitHub Desktop.
import { Iterable, Map, List } from 'immutable';
// add fast getter into immutable
const accesor = new Proxy(Object.prototype, {
get: (target, property, receiver) => target.get(property),
});
Object.setPrototypeOf(Iterable.prototype, accesor);
// now you can do:
const m = Map({ a: 1 });
m.get('a'); // 1
m.a // 1
m.map(..)
m.merge(..)
..
const l = List(['a', 'b']);
l[0] // 'a'
..
// you can use immutable with classic libraries
// you can forget about `toJS()`
// TODO: test it in many cases
// see also: https://github.com/facebook/immutable-js/issues/440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment