hashdiff icon indicating copy to clipboard operation
hashdiff copied to clipboard

Use array path when delimiter is false

Open grey-stripe opened this issue 8 years ago • 2 comments

Addresses #19 and #25.

I went through some effort to make this backwards compatible - no external-facing behavior should be different using default options. This could be made simpler by breaking the default behavior, so let me know which you would prefer.

User-facing changes:

  • The :delimiter option now takes false, in which case paths are returned as arrays rather than strings (#19).
  • Added a new option :stringify_keys, defaulting to true.
    • When false, object keys will not be converted to strings in array paths.
    • This should allow for diffing of objects where symbol keys have meaning (#25).
    • This only applies if :delimiter is false.
  • patch! and unpatch! work automatically with array paths, no option necessary.
  • Added README.md description of new option values.

Internal changes:

  • :prefix is now maintained in all relevant functions (most notably missing was diff_array).
    • When a change is added to the result set, it contains the fully qualified path and does not need an extra step to finalize it.
  • Paths are now maintained internally as array paths rather than string paths.
    • When :delimiter is in effect, these paths will be translated to string paths at the API boundaries.
    • '[*]' in string paths is now -1 in array paths (only exposed in comparison callbacks).
  • Broke diff_object out of diff, similarly to diff_array.
  • diff is now a wrapper for diff_internal
    • Primarily, this was to provide the API boundary for translating back to string paths.
    • Option default values are now applied once here, not every recursive call to diff_internal.
  • Removed several default values on options (most weren't used except in tests).
    • Let me know if this is too intrusive, I may have gotten carried away.
  • Added tests for the new behavior.

grey-stripe avatar Jan 11 '17 01:01 grey-stripe

Thanks @grey-stripe , it looks great 👍 Sorry I somehow missed the PR notification.

You mentioned we it could be simpler by breaking the default behavior. I think I'm now happy to make a major release to break backward-compatibility, and make array diff the default. Could you update the PR?

liufengyun avatar Feb 21 '17 03:02 liufengyun

@liufengyun - thanks for taking a look! I removed the delimiter option so it no longer needs to translate array paths to string paths at the library boundaries. I left patch backwards compatible because it did not complicate any of the rest of the implementation, and (at least in my case) I have old patch diffs stored, and would like them to keep working when I upgrade.

Let me know if you'd like any other changes made.

grey-stripe avatar Feb 23 '17 00:02 grey-stripe