-
Notifications
You must be signed in to change notification settings - Fork 933
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
Run stateReducer over stateToSet passed to onInputValueChange #830
Conversation
55dc091
to
ba4f826
Compare
…lueChange function
ba4f826
to
3da6bae
Compare
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. |
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. |
There was a problem hiding this 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
Outdated
onInputValueChange: onInputValueChangeSpy, | ||
}) | ||
selectItem('bar') | ||
expect(onInputValueChangeSpy).toHaveBeenCalledTimes(0) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@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 |
What: Fixes #819
Why: Right now depending on how
internalSetState
is being called (as a state object or function) thestateAndHelpers
param has either been run through thestateReducer
or it hasn't, this PR addresses this and makes both implementations work the same.How: I run the
stateToSet
through thestateReducer
and pass that state to theonInputValueChange
function, exactly how it's being done within the functionalsetState
just below.Checklist:
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.