Object returned from bindActionCreators() should only include functions #1329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the input object to
bindActionCreators
is not filtered to include just functions. Because of this, the return value may include weird things. For example, if you put action constants intoactions.js
together with action creators, the object returned bybindActionCreators
(and potentially merged into your props if you use React) will include keys likeMY_CONSTANT
. The values under these keys will be broken functions that attempt to dispatch the result of callingMY_CONSTANT
(and, obviously, failing). This is a buggy behavior that could not be relied upon in any way (it would crash if you tried to call those functions) so fixing it isn’t a breaking change.While fixing it, I went with hardcoding some
for
loops instead ofmapValues
/pick
to have better control over where we are allocating and iterating over things and why. I’m not counting on performance improvements from this but I don’t want topick
and thenmapValues
when I can do this with a single allocation, and now that I write custom code inbindActionCreators
, I might as well do it incombineReducers
and hoist theObject.keys()
call outside the combined reducer.Incidentally this also means we don't need utilities from Lodash other than
isPlainObject
. (cc @jdalton)Hopefully I'm not making the perf worse with this 😅