intelie / immutable-js-diff

MIT License
261 stars 32 forks source link

Include old values in 'replace' ops. #12

Closed ds300 closed 7 years ago

ds300 commented 7 years ago

Hi,

First of all, thanks for the great work on this lib 👌 . Not sure if you have any interest in this PR, but it satisfies my use case and I figure it can't hurt to offer.

My use case is as follows: I'm using immutable-js-diff to find out what's changed in a app state tree, and then notify registered listeners if anything pertinent to their interests has changed. Quite a few of the listeners want to know the previous value of the thing that changed, and enabling that manually was becoming a real headache.

The change is simply that e.g.

diff(fromJS({a: 0}), fromJS({a: 1}));
// => List [ Map { "op": "replace", "path": "/a", "value": 1 } ]

becomes

diff(fromJS({a: 0}), fromJS({a: 1}));
// => List [ Map { "op": "replace", "path": "/a", "value": 1, "oldValue": 0 } ]

This could be a breaking change for some people, so no offence will be taken if you laugh me out of the room.