1 2 3 | const Redux = require('redux'); const createStore = Redux.createStore; const store = createStore(reducer); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | const reducer = (state = 'GO', action) => { switch(action.type) { case 'GO': state = 'GO' break; case 'STOP': state = 'STOP' break; case 'CAUTION': state = 'CAUTION'; break; } return state; } |
1 2 3 4 5 6 7 8 9 10 11 | const cautionAction = { type: 'CAUTION' }; const goAction = { type: 'GO' }; const stopAction = { type: 'STOP' } |
1 2 3 4 5 6 7 8 9 10 | // Dispatch actions.................................................... store.dispatch(stopAction); console.log('State: ' + store.getState()); store.dispatch(cautionAction); console.log('State: ' + store.getState()); store.dispatch(goAction); console.log('State: ' + store.getState()); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |