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

feat(hooks): dispatch changes only when needed #1218

Merged
merged 1 commit into from
Jan 20, 2021

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Jan 17, 2021

What:
Only trigger dispatch when state can change.
Also update the tests and add more tests to check rerenders and event preventDefault logic.

Fixes #1097

Why:
To prevent unnecessary rerenders and event.preventDefault.

How:

  • Remove the conditions from the reducers and add them to the hooks instead.
  • If conditions are not met, do not dispatch, do not preventDefault.
  • Add tests to check events and rerenders.
  • Refactor the stateReducer tests.

Breaking behaviors:

  • stateReducer is now called only when the state is about to change, as we already mention in the documentation. This means that if you hit Home/End in an input that has a menu closed, there will be no state change.

Checklist:

  • Documentation
  • Tests
  • TypeScript Types
  • Flow Types
  • Ready to be merged

@silviuaavram silviuaavram force-pushed the feat/trigger-state-only-when-needed branch from c7bd1ba to 8b25677 Compare January 17, 2021 13:33
@codecov-io
Copy link

codecov-io commented Jan 17, 2021

Codecov Report

Merging #1218 (fcdee47) into master (4b6860e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1218   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines         1643      1656   +13     
  Branches       470       478    +8     
=========================================
+ Hits          1643      1656   +13     
Impacted Files Coverage Δ
src/hooks/useSelect/testUtils.js 100.00% <ø> (ø)
src/downshift.js 100.00% <100.00%> (ø)
src/hooks/useCombobox/index.js 100.00% <100.00%> (ø)
src/hooks/useCombobox/reducer.js 100.00% <100.00%> (ø)

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 4b6860e...fcdee47. Read the comment docs.

@silviuaavram silviuaavram force-pushed the feat/trigger-state-only-when-needed branch 3 times, most recently from 35f8f3b to e19c57c Compare January 20, 2021 16:21
@silviuaavram silviuaavram force-pushed the feat/trigger-state-only-when-needed branch from e19c57c to fcdee47 Compare January 20, 2021 16:42
@silviuaavram silviuaavram merged commit a133089 into master Jan 20, 2021
@github-actions
Copy link

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downshift component: Home & End do not move a cursor on input
2 participants