reactrails-react-native-client icon indicating copy to clipboard operation
reactrails-react-native-client copied to clipboard

Reduce action creator boilerplate

Open badnorseman opened this issue 9 years ago • 2 comments

Should we introduce an utils to reduce boilerplate for action creators?

function makeActionCreator(type, ...argNames) {
  return function(...args) {
    let action = { type }
    argNames.forEach((arg, index) => {
      action[argNames[index]] = args[index]
    })
    return action
  }
}

Source: http://redux.js.org/docs/recipes/ReducingBoilerplate.html

badnorseman avatar Jul 10 '16 14:07 badnorseman

IMHO, definitely worth considering.

There are also utility libraries to aid in generating action creators, such as redux-act and redux-actions. These can help reduce boilerplate code and enforce adherence to standards such as Flux Standard Action (FSA).

CC: @robwise @alexfedoseev

justin808 avatar Jul 11 '16 00:07 justin808

I agree, I've always wanted to try this. You could also check out some of the libraries out there:

  • https://github.com/pauldijou/redux-act
  • https://github.com/acdlite/redux-actions

There is also a standard called Flux Standard Action (FSA)

robwise avatar Jul 11 '16 04:07 robwise