Skip to content

updatedDiff() not suitable for nested array? #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lucianobosco opened this issue Aug 9, 2022 · 3 comments
Closed

updatedDiff() not suitable for nested array? #84

lucianobosco opened this issue Aug 9, 2022 · 3 comments

Comments

@lucianobosco
Copy link

lucianobosco commented Aug 9, 2022

Having this original object:

originalResource = {
  id: null,
  name: null,
  tags: [],
  coordinates: null,
  transforms: null
}

And the one with the updated property tags


resource = {
  id: null,
  name: null,
  tags: ['lorem', 'ipsum'],
  coordinates: null,
  transforms: null
}

The result of doing

updatedDiff(originalResource.value, resource.value)
// {}

Am I missing something? I just wanted to use only updatedDiff() method to make things easier.
Any advice will be appreciated

BTW, it would be interesting to have a method just for listing all properties that have been touched. I'm aware about detailedDiff(), but in a plain way with no details could be useful for knowing what properties are "dirty"

@mattphillips
Copy link
Owner

Just looking at the example you've given, it looks like you're invoking updatedDiff with .value on both resources but the value key doesn't exist (so would be undefined) which would yield an empty diff ({}). Can you remove the .value and see if that fixes it?

The touched method is interesting, I suppose my only question would be how would you represent deeply nested diffs on properties?

@lucianobosco
Copy link
Author

My bad, programmer burnout over here.
I'm using Vue 3 composition API and defining consts as reactive, therefore originalResource and resource values should be accessed by using .value

const originalResource = ref({
  id: null,
  name: null,
  tags: [],
  coordinates: null,
  transforms: null
})

const resource = ref({
  id: null,
  name: null,
  tags: ['lorem', 'ipsum'],
  coordinates: null,
  transforms: null
})

console.log( updatedDiff(originalResource.value, resource.value) )

Anyway, I think that using diff() method will be more than enough for what I'm looking for: know the dirty object properties.

Thanks for this library!, I think I will use it in all my projects from now . It's really helpful for knowing what properties are touched and should be sent to the API instead of the whole object in a PATCH request.

@mattphillips
Copy link
Owner

Ha no worries it happens to the best of us, am glad it was a quick one to fix 😆👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants