[Redux] Avoid action type naming conflicts

In redux, the action type is just a normal string type, it is easy to get naming conflicts in large application.

 

Can use namespace-constants lib to solve the problem: https://npmdaily.com/pkg/namespace-constants

 

import constants from 'namespace-constants';

module.exports = constants('todos', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO'
]);
// {
//   'ADD_TODO': 'todos:ADD_TODO',
//   'REMOVE_TODO': 'todos:REMOVE_TODO'
//   'TOGGLE_TODO': 'todos:TOGGLE_TODO'
// }

 

posted @ 2017-02-13 16:04  Zhentiw  阅读(348)  评论(0编辑  收藏  举报