-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
refactor: Use maps and sets instead of plain objects. #6331
Conversation
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.
some minor suggestions, overall lgtm
for (const [key, value] of this.registry_) { | ||
legacyRegistry[key] = value; | ||
} | ||
return object.deepMerge(Object.create(null), legacyRegistry); |
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.
do you really have to deepMerge
again after you just created a new one? I think the old one was just to return a copy, but you're already creating a copy so I think this is redundant.
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.
Here we do, because there's a test verifying that modifying the returned KeyboardShortcut object doesn't affect the one actually stored in the registry, which it would if we don't used deepMerge to deeply clone it. I don't think it's relevant for getKeyMap() though, so removed it there.
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.
but isn't legacyRegistry
already a clone? because on line 205 you're creating a new object. so i don't see how modifying the return value could affect the value of the underlying this.shortcuts
map. but i might be misunderstanding the problem
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 is, but the KeyboardShortcut objects stored in it aren't without the call to deepMerge, so they could still be mutated by the caller and have that affect the contents of the registry.
return; | ||
const variableList = this.variableMap.get(variable.type); | ||
if (variableList) { | ||
for (let i = 0; i < variableList.length; i++) { |
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 think this whole thing can be replaced by
if (variableList && arrayUtils.removeElem(variableList, variable)) {
eventUtils.fire(...);
}
possibly? it's comparing based on the entire VariableModel
instead of checking the ids so it's a little different though
(i didn't know arrayUtils
existed but we use it right above this so why 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.
I'm a little leery to do this since it is a semantic change as you noted - going to leave as-is for now, but we might want to revisit this later.
I discussed performance of Map and Set with primitive keys with @NeilFraser and the rest of the team. Some considerations:
My decision:
|
…istry object and type.
for (const [key, value] of this.registry_) { | ||
legacyRegistry[key] = value; | ||
} | ||
return object.deepMerge(Object.create(null), legacyRegistry); |
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.
but isn't legacyRegistry
already a clone? because on line 205 you're creating a new object. so i don't see how modifying the return value could affect the value of the underlying this.shortcuts
map. but i might be misunderstanding the problem
The basics
npm run format
andnpm run lint
The details
Resolves
Part of #5857
Proposed Changes
This PR uses JS
Map
andSet
objects in places where plain objects were being used due to the absence of those data structures in older versions of Javascript. Only variables that were private have been converted.Reason for Changes
General codehealth and improved typing accuracy.
Test Coverage
Verified tests pass and manually tried the playground.