-
Notifications
You must be signed in to change notification settings - Fork 44
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
Remove d3 map #102
Remove d3 map #102
Conversation
sirahd
commented
May 17, 2017
- remove d3 map
- refactor a little more
- create a copy of options before supplement it, thus preventing causing side-effect to the original object
@domoritz please review this! |
src/parseOption.ts
Outdated
|
||
itemData.each(function (value: string, field: string) { | ||
// prepare title | ||
for (let field of Object.keys(itemData)) { |
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.
You need a hasownproperty here
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 Object.keys()
already returns the properties that's not under prototype chain. So I'm not sure if we need an if to check that again
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 missed that. You are right!
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 definitely use cosnt
here.
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.
for let field of Object.keys()
looks like an overkill. (It will run the loop twice.)
I think better use for..in and hasOwnProperty.
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 the performance is almost the same. At least looking at jsperf. And for in with hasownproperty is not shorter. I'm okay with leaving this as is.
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.
Yeah but this is pretty nonstandard code. While hasOwnProperty is
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've seen all of them but sure, let's go with for in as it is the most standard. Here is the jsperf btw: https://jsperf.com/object-keys-vs-for-in-with-closure/13
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.
- Use const where possible
- replace for of Object.keys with for in
a6fea43
to
b0a377a
Compare
@domoritz Please ignore the first 4 commits. It was because I rebase onto master. |
Is this done? |
Yes. You can merge it. |
🚀 PR was released in |