Created
October 27, 2017 22:40
-
-
Save a-x-/63f84a5e726cc00c644f0cdfe8ab929f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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