flitbit / diff

Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
MIT License
2.99k stars 213 forks source link

Purpose of lhs in differences? #184

Open Danieltech99 opened 1 year ago

Danieltech99 commented 1 year ago

Why is the lhs property created in diff?

Is this only used for revertChange?

I am using this to generate diffs that are stored in a database. If I only apply in one direction (in this case applyChange and not revertChange), am I correct to conclude that lhs is not necessary? Which means it is causing the diff to be unnecessarily large in space.

If this is unnecessary, is there an easy way to omit it from being generated, or should I just map over the differences and remove it?

cerebralkungfu commented 7 months ago

The lhs property is supplied for validation; at the time I authored the library, I needed to ensure the change was being applied to an appropriate object - I defined appropriate as "an object that looks like the object from which the difference was calculated".

That said, most use cases can safely discard lhs.

I am working on a major update, v2.x which includes a compact representation for storage... as time allows.

cerebralkungfu commented 7 months ago

Two more specific cases came to mind while I was working on a pending update. Reverting a change, and auditing a change.

I still use this library in projects to generate audit records, so that case is still relevant for some (like me).

Reverting I tend not to do, but if you choose to "roll back" changes for whatever reason, you do need the prior value, which is what lhs provides.