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

Run stateReducer over stateToSet passed to onInputValueChange #830

Conversation

aaronnuu
Copy link

What: Fixes #819

Why: Right now depending on how internalSetState is being called (as a state object or function) the stateAndHelpers param has either been run through the stateReducer or it hasn't, this PR addresses this and makes both implementations work the same.

How: I run the stateToSet through the stateReducer and pass that state to the onInputValueChange function, exactly how it's being done within the functional setState just below.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

I have added a couple of tests that make sure the bugs that I identified aren't a problem anymore, not sure if they're done in the best way or not though so any feedback on that one would be appreciated.

@aaronnuu aaronnuu force-pushed the fix/on-input-value-change-state-reducer branch 2 times, most recently from 55dc091 to ba4f826 Compare November 25, 2019 23:30
@aaronnuu aaronnuu force-pushed the fix/on-input-value-change-state-reducer branch from ba4f826 to 3da6bae Compare November 25, 2019 23:34
@silviuaavram
Copy link
Collaborator

It took me too much, but arrived at this issue and aiming to close it. @aaronnuu are you still interested in merging this? If so I have a few comments, if not i will create a PR myself. issue makes sense, so we should merge the reviewed changes.

@aaronnuu
Copy link
Author

I haven't been following the hooks development very closely so if it makes more sense to open a new PR I'm not against it, otherwise yeah still interested in helping out.

Copy link
Collaborator

@silviuaavram silviuaavram left a comment

Choose a reason for hiding this comment

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

Also can you please run build again and replace the snapshot? After this we should be good to go, thank you for these changes!

src/__tests__/downshift.lifecycle.js Show resolved Hide resolved
src/__tests__/downshift.lifecycle.js Show resolved Hide resolved
onInputValueChange: onInputValueChangeSpy,
})
selectItem('bar')
expect(onInputValueChangeSpy).toHaveBeenCalledTimes(0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

.not.toHaveBeenCalled()

...stateToSet,
})
if (!isStateToSetFunction) {
const newStateToSet = this.props.stateReducer(this.state, stateToSet)
Copy link
Collaborator

Choose a reason for hiding this comment

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

no reason to call this unless newStateToSet.hasOwnProperty('inputValue') so I would leave the condition as it was and call this before calling onInputValueChange

Copy link
Author

@aaronnuu aaronnuu May 12, 2020

Choose a reason for hiding this comment

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

I had it this way originally but ran into some issues since the user can add or remove inputValue with the stateReducer so this ensures that onInputValueChange will be called (or not called) if they add / remove it

Copy link
Author

Choose a reason for hiding this comment

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

I might add a comment for this because it's a bit of a gotcha

@aaronnuu aaronnuu requested a review from silviuaavram May 30, 2020 06:10
@aaronnuu
Copy link
Author

@silviuaavram Sorry it took a couple of weeks, have made those changes and re-run the snapshot. Wasn't sure how to replicate the helper object that gets sent as the second param to the onInputValueChange function so just verifying it's any object.

@silviuaavram silviuaavram added bug wip Work in progress labels Jun 19, 2020
@aaronnuu aaronnuu closed this May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug wip Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"stateAndHelpers" param within "onInputValueChange" function does not align with desired state
2 participants