Skip to content

Using dataSource[dataKey] leads to false results #197

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

Merged
merged 2 commits into from
Apr 30, 2020

Conversation

tiptronic
Copy link
Contributor

@tiptronic tiptronic commented Apr 29, 2020

Using dataSource[dataKey] has 2 issues:

  1. It searches the complete prototype chain (which is unefficient)
  2. If the resolved value is 0 or false the result is false (which isn't intended)

Example:
dataKey is 'id', it's value is zero:
e.g.
{
id: 0
}

So better to be explicit here, e.g. 👍
if(dataSource.hasOwnProperty(dataKey))

What kind of this PR? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Build-related changes
  • Other, please describe:

Other information:

Using `dataSource[dataKey]` has 2 issues:
1. It searches the complete prototype chain (which is unefficient)
2. If the resolved value is `0` or `false` the result is `false` (which isn't intended)

Example:
dataKey is 'id', it's value is zero:
e.g.
{
   id: 0
}

So better to be explicit here, e.g. 👍 
` if(dataSource.hasOwnProperty(dataKey)) `
@tangbc
Copy link
Owner

tangbc commented Apr 29, 2020

Good suggestion, but you need fix eslint error.

@tiptronic
Copy link
Contributor Author

just fixed the linting error

@tangbc tangbc merged commit 47d68f5 into tangbc:master Apr 30, 2020
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.

2 participants