benjamine / jsondiffpatch

Diff & patch JavaScript objects
MIT License
4.79k stars 466 forks source link

How does it take advantage of immutability? #241

Open jiayihu opened 6 years ago

jiayihu commented 6 years ago

Does the lib skip work by checking if two objects are the same reference? I'd need an implementation of deep-diff which can short-circuit if immutability is followed. In ecosystems like React/Redux it's a very common pattern.

Anyway thanks for you work, the small foot-print delta is exactly what I need.

mikeyoon commented 6 years ago

As far as I can tell, it has no ability to stop traversing. I'd think it'd be hard to know if subtree is really immutable unless the library had some deeper understanding of your objects. Probably would need to add a feature that could call a function on each successful equality check to see if it is immutable, and stop traversing that subtree if it returns true.