Closed dheerajaggarwal closed 11 years ago
Hi, answering your questions:
1 - Yes, this is expected, the diff is saying {"b":"c"} got removed from index 0, and {"b":"c"} got added at index 0. The reason is when comparting array items, jsondiffpatch can't guess two objects are the same unless you provide a hash function (or they are equal by ref, ie. the same object).
Check this is an example taken from README:
jsondiffpatch.config.objectHash = function(obj) { obj.id || JSON.stringify(obj); };
Realize this function will only be executed once per object (the result gets cached) and only when objects being compared are not equal by reference (the same object, or a value type). using JSON.stringify might be a bit more costy than a recursive comparison of object fields (which you could easily write), but might be good enough for most cases.
Note the DEMO page uses a very similar objectHash function and you can test no diff is produced there using the data in your example.
2 - I apologize, there's no docs on reading the delta yet, but they are pretty simple, here's the basics:
Hi Benjamine, Thanks a lot for your answers. Yes, it is working after adding objecthash. :)
I have some more questions, will get back to you soon.
Ok, no problem, closing this one then.
Hi, From the first look, I liked your library very much. But now, I am in trouble, trying the following code:
And I am getting the following output:
Two questions:
Any help is appreciated.