- ACTIONS
- REDUCER
- DISPATCHER
- git clone [email protected]:tsaowe/redux-cli.git
- cd redux-cli
- mkdir .redux
- touch .redux/actions.json
vim .redux/actions.json
{
"setFileStatus": ["filePath","mode"],
"setActiveIndex": ["index","parent"],
"openWindow": []
}
-
node src/index.js
-
cat .redux/output.js
import produce from "immer"
/***************************************ACTIONS start******************************************************************/
export const ACTIONS = {
SET_FILE_STATUS: 'REDUX-CLI@SET_FILE_STATUS',
SET_ACTIVE_INDEX: 'REDUX-CLI@SET_ACTIVE_INDEX',
OPEN_WINDOW: 'REDUX-CLI@OPEN_WINDOW'
};
/***************************************ACTIONS end ******************************************************************/
/***************************************reducer start******************************************************************/
export const reducer = (state = []/*todo*/, action) => {
const {type} = action;
switch (type) {
case ACTIONS.SET_FILE_STATUS:
const {filePath, mode} = action;
return produce(state, draftState => {
// todo
});
case ACTIONS.SET_ACTIVE_INDEX:
const {index, parent} = action;
return produce(state, draftState => {
// todo
});
case ACTIONS.OPEN_WINDOW:
return produce(state, draftState => {
// todo
});
default:
return state;
}
};
/***************************************reducer end********************************************************************/
/***************************************dispatcher start***************************************************************/
export const dispatchers = {
setFileStatus: (filePath, mode) => ({
type: ACTIONS.SET_FILE_STATUS,
filePath,
mode
}),
setActiveIndex: (index, parent) => ({
type: ACTIONS.SET_ACTIVE_INDEX,
index,
parent
}),
openWindow: () => ({
type: ACTIONS.OPEN_WINDOW
})
};
/***************************************dispatcher end*****************************************************************/
I use immer as my immutable state tool, but you can use your own immutable~ enjoy
Any feature or suggestion please submit an issue