Closed lucianobosco closed 2 years ago
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?
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.
Ha no worries it happens to the best of us, am glad it was a quick one to fix 😆👍
Having this original object:
And the one with the updated property
tags
The result of doing
Am I missing something? I just wanted to use only
updatedDiff()
method to make things easier. Any advice will be appreciatedBTW, 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"