Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(pickState): only pick relevant state #183

Merged
merged 1 commit into from
Sep 11, 2017
Merged

feat(pickState): only pick relevant state #183

merged 1 commit into from
Sep 11, 2017

Conversation

tansongyang
Copy link
Collaborator

Make toggleMenu and friends more user-friendly by only picking out
state that is relevant to downshift, allowing users to use them as event
event handlers. See #182.

What: Make toggleMenu and friends more user-friendly.

Why: See #182.

How: Add pickState and call it whenever we are about to spread otherStateToSet into internalSetState

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Additional comments:

  1. When I initially pulled the most recent from master, npm run validate failed.

     FAIL  other\__tests__\build.js
      ● Test suite failed to run
    
      Cannot find module '../../dist/downshift.es' from 'build.js'
    
        at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
        at Object.<anonymous> (other/__tests__/build.js:14:18)
    
     FAIL  other\__tests__\preact.js
      ● Test suite failed to run
    
      Cannot find module '../../dist/downshift.preact.cjs' from 'preact.js'
    
        at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
        at Object.<anonymous> (other/__tests__/preact.js:22:24)
    

    I investigated a bit. Only the build-and-test task is failing. lint, test:cover, and test:ts succeed. I decided to ignore it while developing because I could still run the other test tasks, thinking it could just be a problem with my machine. Please let me know if we should address this first.

  2. I wanted to add direct tests on toggleMenu and others to downshift.misc.js (in addition to adding utils.pick-state.js), but there wasn't a way to test what object was being passed to internalSetState. No matter what the internal state is, we always pass the correct keys to render (https://github.com/paypal/downshift/blob/master/src/downshift.js#L336). So, with the current test setup, I couldn't find a way to see what the internals were. I decided it was OK, thinking the new test was sufficient, but let me know if you think otherwise.

  3. Locally, I added a new story to test the changes. It didn't seem appropriate to include it in the commit, but let me know if you think otherwise.

Make `toggleMenu` and friends more user-friendly by only picking out
state that is relevant to downshift, allowing users to use them as event
event handlers. See #182.
@codecov-io
Copy link

Codecov Report

Merging #183 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #183   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines         267    277   +10     
  Branches       64     65    +1     
=====================================
+ Hits          267    277   +10
Impacted Files Coverage Δ
src/utils.js 100% <100%> (ø) ⬆️
src/downshift.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1490f0...ba80dd8. Read the comment docs.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Looks super! Just one idea.

@@ -154,6 +155,7 @@ class Downshift extends Component {
highlightedIndex = this.props.defaultHighlightedIndex,
otherStateToSet = {},
) => {
otherStateToSet = pickState(otherStateToSet)
Copy link
Member

Choose a reason for hiding this comment

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

Actually, I think this is the only place we really need this function called because all the other code paths lead here. Try removing the other changes and see if this works. I think it will.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just tried this, and it didn't work for me. I also tried to move this further down into internalSetState, and that didn't remove the warnings either.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Looks perfect! thanks!

@kentcdodds kentcdodds merged commit 1cb2743 into downshift-js:master Sep 11, 2017
@tansongyang tansongyang deleted the issue182 branch September 11, 2017 16:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants