大众点评(redux架构)

action

发起的行为动作
reducer
处理器
reducer=(state,action) //在处理器中放置上次保存的状态和即将要做的行为

state
最后的状态
如果用react发送ajax请求 【大众点评(redux架构)】action=>发起Ajax请求
reducer=>处理json数据
state=>渲染到UI
源码解读
const initlState={}; const action={ type:'init', payload:'hello world', }; //action必须为对象 const reducer=(state,action)=>{ return Object.assign({}, action); //return action; } //createStore()返回以函数为属性的对象 const store=createStore(reducer,initlState); //store.dispatch(action)会调用reducer(store.getState(),action),结果返回给currentState这个闭包量 store.dispatch(action); //store.getState()返回闭包量currentState console.log(store.getState());

    推荐阅读