Added ability to display function name as actionType #492
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.
Reason
This PR seeks to start the process of change. If the official Redux-devtools supports action types that aren't strings, then other libraries and utilities (which may already have no preference) will follow suit.
Abstract
The normal advice is that
actionType
should be a string. This is purely for debugging purposes. If the tools used for debugging were altered, then it would be easier to use something other than a string.Using a function means you don't have to have a separate action variable from the action creator itself:
Redux doesn't care if your action type is a string, object, symbol or whatever. Even @gaearon noted it should be a Symbol for uniqueness, but only said to use strings because of the debugging potential.
Another benefit of using functions is you're only comparing memory references rather than strings. This is a performance boost, but probably not one that will manifest in most applications.
We could even take this further to include
symbol.description
andclassInstance.constructor.name
.Downfalls
The one downfall is most Redux tooling both utilizes and expects strings. This would need to change. Even
createReducer
would need to take aMap
of actions instead of anObject
or this wouldn't work.Alternatives
Without making a change to Redux-devtools, we could instead rely on using:
This requires knowing certain action types are functions rather than strings. In an application where you might be iteratively updating action types, this would pose a problem.