Since string comparisons in switch statement are expensive, why not compare references instead?
If my understanding is wrong, please let me know.
strings:
one() {
dispatch({ type: 'ONE', payload: 1})
}
references:
export one() {
dispatch(one, 1)
}
then instead of
switch (action.type) {
case 'ONE': ...
case 'TWOTWO': ...
}
this
import {actions} from './actions'
switch (action) {
case actions.one: ...
case actions.twoTwo: ...
This is entirely up to your action creators and reducers. But string comparison won't be a serious bottleneck compared to other things going on with your reducers re-building state and your eventual display logic running. You're doing a premature optimization.
Most helpful comment
This is entirely up to your action creators and reducers. But string comparison won't be a serious bottleneck compared to other things going on with your reducers re-building state and your eventual display logic running. You're doing a premature optimization.