标签:ret javascrip run reducer rom res action ams esc
redux-actions
有两大法宝createAction
和handleActions
.
原来创建action
:
const startAction = () => ({ type: START });
使用redux-actions
创建action
:
import { createAction } from ‘redux-actions‘;
const startAction = createAction(START);
原来reducer
操作state
写法要使用switch
或if else
来匹配:
function timer(state = defaultState, action) {
switch (action.type) {
case START:
return { ...state, runStatus: true };
case STOP:
return { ...state, runStatus: false };
case RESET:
return { ...state, seconds: 0 };
case RUN_TIMER:
return { ...state, seconds: state.seconds + 1 };
default:
return state;
}
}
使用redux-actions``reducer
操作state
:
const timer = handleActions({
START: (state, action) => ({ ...state, runStatus: true }),
STOP: (state, action) => ({ ...state, runStatus: false }),
RESET: (state, action) => ({ ...state, seconds: 0 }),
RUN_TIMER: (state, action) => ({ ...state, seconds: state.seconds + 1 }),
}, defaultState);
http://blog.csdn.net/sinat_17775997/article/details/70176723
标签:ret javascrip run reducer rom res action ams esc
原文地址:http://www.cnblogs.com/yeziTesting/p/7462235.html