Fuck off constants.js and global constants in react/flux/redux/wateva.
- Drop all of your files about constants, react-constant will take care for you.
- Namespaced constants, never worry about conflict with other component in your project.
- 2.2KB minified, extreme slim.
npm install react-constant --save
//ES5 version
var Contant = require('react-constant');
var constants = Constant('mynamespace');
//ES6 version
import Constant from 'react-constant';
const constants = Constant('mynamespace');
<script src="dist/constant.min.js"></script>
reducer.js
function reducer(state, action){
switch(action.type){
case constants.of('ON'):
//TODO
break;
case constants.of('OFF'):
//TODO
break;
default:
return state;
}
}
action.js
function toggleLight(flag){
return {
type: constants.ON,
flag: flag
}
}
- Redux for build and test template
MIT