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

null check in nested key resolution #32

Merged
merged 5 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const tests = {
},
'can handle objected with nested keys': {
input: [
[{name: {first: 'baz'}}, {name: {first: 'bat'}}, {name: {first: 'foo'}}],
[{name: {first: 'baz'}}, {name: {first: 'bat'}}, {}],
Copy link
Owner

Choose a reason for hiding this comment

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

Could you actually add another item to the array? This test is also ensuring that we filter out the foo item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right gotcha.

'ba',
{keys: ['name.first']},
],
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function getItemValues(item, key) {
// handle nested keys
value = key
.split('.')
.reduce((itemObj, nestedKey) => itemObj[nestedKey], item)
.reduce((itemObj, nestedKey) => itemObj && itemObj[nestedKey] ? itemObj[nestedKey] : null, item)
Copy link
Owner

Choose a reason for hiding this comment

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

The second part of the && is unnecessary here

} else {
value = item[key]
}
Expand Down