Skip to content
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

Merged
merged 2 commits into from Sep 10, 2020
Merged

renameAll deleting keys #39

merged 2 commits into from Sep 10, 2020

Conversation

jesspoemape
Copy link
Contributor

For #38

Collaborator: @rpearce

@jesspoemape jesspoemape requested review from flintinatux and a team and removed request for flintinatux September 1, 2020 14:57
src/renameAll.js Outdated

for (let k in obj) {
newObj[k] = obj[k]
}
Copy link
Contributor

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

Copy link
Member

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]
}

Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Contributor

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?"

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty slick

Copy link
Contributor

@spencerfdavis spencerfdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌚

@evilsoft
Copy link

evilsoft commented Sep 1, 2020

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 pick or omit.

I would think that with a name like renameAll it is expected that all keys should be provided.
Would it make more sense to create a new function called renameSome?

@rpearce
Copy link
Contributor

rpearce commented Sep 1, 2020

@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 A to B and C to A -- the current implementation will delete A entirely if it is in the wrong order inside the renaming object.

@jesspoemape did I frame this correctly?

@evilsoft
Copy link

evilsoft commented Sep 1, 2020

@rpearce ah, yes, good point I see that now.
Makes sense!

@jesspoemape jesspoemape merged commit 15b49bd into master Sep 10, 2020
@jesspoemape jesspoemape deleted the update-rename-all branch September 10, 2020 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants