|
|
|
|
|
by hex13
3227 days ago
|
|
I've build a library Transmutable which falls into the third category :) it allows to use immutable data structures in mutable-like way, using plain assignments:
https://www.npmjs.com/package/transmutable
(mutations are not performed but they are just recorded in ES6 Proxy, and object is cloned on commit (sort of copy-on-write), and mutations are then applied). So it basically enables for writing such things: const copy = transform(original, stage => {
stage.x = 10;
stage.y = 20;
stage.foo.bar = 123;
})
instead of Object.assign / ... mess. |
|
The only issue with it is, of course, the fact that Proxies are ES6 and everyone still has to deal with old browsers.
I know MobX does similar object observation, and they support IE, but I've never had the time to go into their codebase. Do you know if something like this could be written in a way that allows IE10/11 to support it?
Also, could you elaborate on why it's necessary to use a proxy at all, when in reality you could just do a copy of the object from the very beginning and allow them to do mutations on that?