redux的四个步骤简化

import { createStore } from 'redux';
//定义计算规则
function counter( aa = 0, action ) {
    switch (action.type){
        case 'tp1':
            return aa + 1;
        case 'tp2':
            return aa - 2;
        default:
            return 10;
    }
}
//根据计算规则生成store
let store = createStore(counter);
//定义store变化的派发规则
store.subscribe(()=>{
    console.log('current state', store.getState());
});
//触发数据变化
store.dispatch({type:'tp1'});

redux可以简化成四个步骤,这是在慕课网上wangfupeng1988 讲的,手记是公开的,写在这备注下,http://www.imooc.com/article/14958

随机浏览