Skip to content

Solution for simple action creation without string constants and less magic  #628

Closed

Description

Image for: Description

I was little annoyed by string constants as action types. And write solution for this, need for objective criticism and ideas. The solution is create action as class methods, and make method name accesible.

@EasyActions
class Actions {
   USER_ACTION(type, id){
        return {type, id}
   }
}
export default new Actions(); 

---
import Action from './actions';

dispatch(Actions.USER_ACTION(42))

switch(action.type) {
   case Actions.USER_ACTION:
       // return state
}

More info and examples here: https://github.com/grigory-leonenko/redux-easy-actions

Metadata

Image for: Metadata

Metadata

Image for: Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Image for: Issue actions