Skip to content

Revert List component to old API #62

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 4 commits into from
Jun 21, 2018
Merged

Revert List component to old API #62

merged 4 commits into from
Jun 21, 2018

Conversation

jimbo
Copy link
Contributor

@jimbo jimbo commented Jun 20, 2018

This PR is a:

[ ] New feature
[ ] Enhancement/Optimization
[x] Refactor
[ ] Bugfix
[ ] Test for existing code
[ ] Documentation

Summary

When this pull request is merged, it will...

Change the List component's API, such that it only expects items to be an iterable, instead of a stricter, Map-compatible, two-dimensional iterable. This change will make it more expedient to pass collections of data straight from the API to List without having to transform them first.

Additional information

Since we can't safely mandate that all collections consist of objects with an id property, List must also accept a key-generation function, getItemKey. This function will default to ({ id }) => id, which plucks the id prop from a plain object, covering the most common case. For flat collections of strings, such as tags, users can supply an identity function; for more unusual collections where the primary key is something other than id, they can supply a custom function.

This PR is marked [WIP] until this API change is approved. Once approved, instances of List in this repo have to be updated.


if (prop != null && !isIterable(prop)) {
return new Error(
`Invalid prop \`${propName}\` supplied to \`${componentName}\`. Validation failed.`
Copy link
Contributor

@DrewML DrewML Jun 20, 2018

Choose a reason for hiding this comment

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

Can we make this message more specific? Doesn't seem to call out that we're expecting an iterable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DrewML Updated. 👍

@DrewML
Copy link
Contributor

DrewML commented Jun 21, 2018

Thanks for doing this! Good that it now works seamlessly with our payloads, but can be useable by others with differently-shaped data.

DrewML
DrewML previously approved these changes Jun 21, 2018
@jimbo jimbo changed the title [WIP] Revert List component to old API Revert List component to old API Jun 21, 2018
@jimbo jimbo force-pushed the jimbo/list-api-change branch from 31b5af6 to b8481a5 Compare June 21, 2018 16:44
@jimbo
Copy link
Contributor Author

jimbo commented Jun 21, 2018

No problem, it's just a different approach to the same solution.

Fixes #41.

jimbo added 4 commits June 21, 2018 11:03
Instead of accepting a Map-compatible iterable for items, accept
an Array-compatible iterable and a keymaking function `getItemKey`.
@jimbo jimbo force-pushed the jimbo/list-api-change branch from b8481a5 to 6e040ba Compare June 21, 2018 18:04
@coveralls
Copy link

Pull Request Test Coverage Report for Build 132

  • 16 of 23 (69.57%) changed or added relevant lines in 7 files are covered.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 66.839%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/venia-concept/src/components/Select/select.js 0 1 0.0%
packages/venia-concept/src/components/ProductOptions/tileList.js 0 2 0.0%
packages/venia-concept/src/components/ProductOptions/swatchList.js 0 2 0.0%
packages/venia-concept/src/components/ProductImageCarousel/thumbnailList.js 0 2 0.0%
Files with Coverage Reduction New Missed Lines %
packages/peregrine/src/List/item.js 11 0.0%
Totals Coverage Status
Change from base Build 131: -0.2%
Covered Lines: 757
Relevant Lines: 1184

💛 - Coveralls

@jimbo jimbo merged commit 66b25a4 into master Jun 21, 2018
@jimbo jimbo deleted the jimbo/list-api-change branch June 21, 2018 19:51
@jimbo jimbo mentioned this pull request Nov 27, 2018
6 tasks
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.

3 participants