From 62957d24722c420c98936e5806b72a849cb00e3c Mon Sep 17 00:00:00 2001 From: Kevin Ghadyani <3948069+Sawtaytoes@users.noreply.github.com> Date: Wed, 30 Oct 2019 14:28:45 -0500 Subject: [PATCH] Added ability to display function name as actionType The normal advice is that `actionType` should be a string. This is purely for debugging purposes. If the tools used for debugging are 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: ```js some someActionCreator = () => ({ type: someActionCreator, }) ``` 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` and `classInstance.constructor.name`. The one downfall is most Redux tooling both utilizes and expects strings. This would need to change. Even `createReducer` would need to take a `Map` of actions instead of an `Object` or this wouldn't work. --- packages/redux-devtools-inspector/src/ActionListRow.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/redux-devtools-inspector/src/ActionListRow.jsx b/packages/redux-devtools-inspector/src/ActionListRow.jsx index 838ca567..10207446 100644 --- a/packages/redux-devtools-inspector/src/ActionListRow.jsx +++ b/packages/redux-devtools-inspector/src/ActionListRow.jsx @@ -76,7 +76,11 @@ export default class ActionListRow extends Component { isSkipped && 'actionListItemNameSkipped' ])} > - {actionType} + { + typeof actionType === 'function' + ? actionType.name + : actionType + } {hideActionButtons ? (