Closed icebob closed 6 years ago
Thank you for the feedback! Yeah I've been a little torn about the same scenario that you describe. The push
technically modifies user.roles
but we're also setting a value for user.roles.1
at the same time. If I recall correctly I tried to make the changes
callback receive a set of changes that most closely resembles what the native Proxy
object reports.
I'm heading out the door to go backpacking until Sunday so unfortunately I can't respond for the next couple days, but I'll follow-up as soon as I return.
@icebob I'm back home now and I took a closer look at this -- your suggestion makes perfect sense. I'll make that modification today and push out the change shortly.
If you'd prefer to make the change yourself and submit the PR, please feel free to do so!
Hi @ElliotNB, great. I'm on vacation right now, so maybe I will able to help next week.
@icebob I went ahead and implemented a fix for this. If you get the chance, please let me know if you notice any other issues with currentPath
for arrays.
Thanks again for the feedback!
Thanks @ElliotNB, I'm checking...
Hi, I tested, and it's working properly! :+1:
Maybe someone else would be useful, this is my small code which rebuilds the object by changes (uses lodash's set
& unset
functions):
changes.forEach(c => {
if (c.type == "add" || c.type == "update") {
_.set(obj.__getTarget, c.currentPath, _.cloneDeep(c.newValue));
} else if (c.type == "delete") {
_.unset(obj.__getTarget, c.currentPath);
}
});
Hi, your lib is great. I'm trying to use it in my project, but I have a problem. According to changes I want to reproduce the object and I use the
currentPath
andnewValue
fields. When I push an item to an array, thecurrentPath
not too exact.Example
Output
So when I use the
roles.push
thecurrentPath
doesn't contain the index, just theproperty
. But when I update object, thecurrentPath
contains theproperty
field too. I think the correctcurrentPath
should beuser.roles.1
. What do you think?Reproduce jsFiddle: https://jsfiddle.net/icebob/rtvcn685/
Thanks, Icebob