Palindrom / JSONPatcherProxy

ES6 proxy powered JSON Object observer that emits JSON patches when changes occur to your object tree.
94 stars 14 forks source link

Add "oldValue" to a patch #28

Open dntzhang opened 5 years ago

dntzhang commented 5 years ago

https://github.com/Tencent/omi

Hope to support oldValue:

{op: "replace", path: "/a/b", value: "aaa2", oldValue: "aaa1"}

If it is convenient, you can review this for omi. I added only one line of code. https://github.com/Tencent/omi/blob/master/packages/omi/src/proxy.js#L149

warpech commented 5 years ago

Thanks @dntzhang for the kind words. I took the liberty to rename the title to reflect the content of your comment.

oldValue is not part of the JSON Patch standard, but maybe we could either:

  1. implement this as a non-enumerable property
  2. or, add it as a second argument to the observed callback