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.
This commit is contained in:
Kevin Ghadyani 2019-10-30 14:28:45 -05:00 committed by GitHub
parent 03d1448dc3
commit 62957d2472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,7 +76,11 @@ export default class ActionListRow extends Component {
isSkipped && 'actionListItemNameSkipped'
])}
>
{actionType}
{
typeof actionType === 'function'
? actionType.name
: actionType
}
</div>
{hideActionButtons ? (
<RightSlider styling={styling} shown>