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
Arrays are not copied properly - keys are lost #52
Comments
- Solves this issue where additional array keys were not preserved: kolodny/immutability-helper#52
Thanks for the feedback. This has been fixed in |
Awwsome! |
$push and $unshift lose keys as well. I had to change them. How do you reopen issues in github? $push: function(value, nextObject, spec) {
invariantPushAndUnshift(nextObject, spec, '$push');
- return value.length ? nextObject.concat(value) : nextObject;
+ if (value.length) {
+ nextObject = copy(nextObject)
+ nextObject.push.apply(nextObject, value)
+ }
+ return nextObject;
},
$unshift: function(value, nextObject, spec) {
invariantPushAndUnshift(nextObject, spec, '$unshift');
- return value.length ? value.concat(nextObject) : nextObject;
+ if (value.length) {
+ nextObject = copy(nextObject)
+ nextObject.unshift.apply(nextObject, value)
+ }
+ return nextObject;
}, |
var a = ['w','x','y']
a.foo = 'bar'
var b = a.concat(['z'])
b.foo === undefined The reason why this isn't true in I'd suggest overriding the |
What you just did was a concat, not a push... Push doesn't lose keys at
all.
…On 17 Jul 2017 02:06, "Moshe Kolodny" ***@***.***> wrote:
$push and $unshift should lose keys. Consider the following:
var a = ['w','x','y']a.foo = 'bar'var b = a.concat(['z'])b.foo === undefined
The reason why this isn't true in $set is because $set is a replacement
for doing a[prop] = value which the object "returned" would retain any
properties that existed in the array.
I'd suggest overriding the $push and $unshift directives to support non
standard keys to be retained in the next object
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#52 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUjq6ctQBiPMU8GdKru6K1HOJSLjrh6ks5sOrOXgaJpZM4OUHVC>
.
|
Yes |
I think $push and $unshift should match .push and .unshift. No?
…On 18 July 2017 at 15:27, Moshe Kolodny ***@***.***> wrote:
Yes $push is basically a concat, meaning a new object is expected, as
opposed to a set which is just reusing the old object
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#52 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUjq8mabvos0B4TC-ibsjCN9RX_zI0lks5sPMDFgaJpZM4OUHVC>
.
|
If |
I agree that |
Consider:
Notice the "top" key was lost. The culprit is (I believe) line 22 where it should be:
Keys should not be lost.
The text was updated successfully, but these errors were encountered: