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
renameAll deleting keys #39
Conversation
src/renameAll.js
Outdated
|
||
for (let k in obj) { | ||
newObj[k] = obj[k] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One less thing to polyfill, IMO, but I don't think we're willing to die on this object copying hill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we iterating twice anyway? Can we get by with iterating over obj
once?
I just did this elsewhere. Is just for rename
, but same principle: https://github.com/articulate/authentic/pull/21/files#diff-27a1c86133de4310373decfdad200a91R1
I think is may also solve this problem if you don't have to track state of what we've already touched.
const newObj = {}
for (let prevKey in obj) {
const nextKey = renames[prevKey] || prevKey
nextObj[nextKey] = obj[prevKey]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It keeps it as close to the original implementation as possible, but if this is a better idea, then ✅ . @jesspoemape want to give it a go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-read my comment, & i think i came off stronger than i intended. Apologies.
Nevertheless, if we can resolve the problem by removing complexity instead of adding, i think feel we should. Unless there's a detail i'm missing somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This is that hill I was talking about not being willing to die on.)
Short of refactoring how you suggest (up to Jessica if she wants to), the alternative would be to take out the loop and put back in the Object.assign
so that the only added complexity is the conditional to determine "do you delete the key or not?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpearce @mgreystone
Just pushed up a refactor as per Markus' suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's pretty slick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌚
Are we 💯 this is not the expected behavior? This seems like a Major breaking change. JIC people relied on this behavior to avoid an additional I would think that with a name like |
@evilsoft the current implementation will either drop or keep a key based on where that key shows up in the renaming object, and this feels like a super accidental bug to me. The scenario is when you want to rename @jesspoemape did I frame this correctly? |
@rpearce ah, yes, good point I see that now. |
For #38
Collaborator: @rpearce