Not exact `currentPath` at array pushing
See original GitHub issueHi,
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
and newValue
fields. When I push an item to an array, the currentPath
not too exact.
Example
let data = {};
let reproduced = {};
var p = ObservableSlim.create(data, true, function(changes) {
console.log(JSON.stringify(changes));
changes.forEach(change => {
_.set(reproduced, change.currentPath, change.newValue);
});
});
p.user = {
roles: ["admin"]
};
p.user.roles.push("member");
setTimeout(function() {
console.log("REPRODUCED OBJECT:", JSON.stringify(reproduced));
}, 2000);
Output
[{"type":"add","target":{"user":{"roles":["admin","member"]}},"property":"user","newValue":{"roles":["admin","member"]},"currentPath":"user","proxy":{"user":{"roles":["admin","member"]}}}]
[{"type":"add","target":["admin","member"],"property":"1","newValue":"member","currentPath":"user.roles","proxy":["admin","member"]}]
REPRODUCED OBJECT: {"user":{"roles":"member"}}
So when I use the roles.push
the currentPath
doesn’t contain the index, just the property
. But when I update object, the currentPath
contains the property
field too. I think the correct currentPath
should be user.roles.1
. What do you think?
Reproduce jsFiddle: https://jsfiddle.net/icebob/rtvcn685/
Thanks, Icebob
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
JavaScript push not pushing correct values - Stack Overflow
Note: The array objects created by slice are shallow copied arrays. ... It's because you push reference to tempArray not a copy. try:...
Read more >Array push not working properly!! - ServiceNow Community
Array push not working properly!! Go to solution. gokulraj. Giga Expert ... Can anyone help me to findout where the exact issue is??...
Read more >Everything You Need to Know About the JavaScript Array ...
Using an array push is helpful when you need to know how many data points are contained in an array or for adding...
Read more >array_shift - Manual - PHP
array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All...
Read more >Array | Apple Developer Documentation
Overview. Arrays are one of the most commonly used data types in an app. You use arrays to organize your app's data. Specifically,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, I tested, and it’s working properly! 👍 Maybe someone else would be useful, this is my small code which rebuilds the object by changes (uses lodash’s
set
&unset
functions):Thanks @ElliotNB, I’m checking…