Redux
store
存儲(chǔ)state,唯一store。
創(chuàng)建store
createStore([reducer], [preloadedState], applyMiddleware([middlewares]))
Provider
reducer
唯一可直接修改state的方式,為function,傳入state,action,返回state一個(gè)新的對(duì)象。
combineReducers
組合多個(gè)reducer
官方示例
rootReducer = combineReducers({potato: potatoReducer, tomato: >tomatoReducer}) // This would produce the following state object { potato: { // ... potatoes, and other state managed by the potatoReducer ... }, tomato: { // ... tomatoes, and other state managed by the tomatoReducer, maybe >some nice sauce? ... } }
action
帶有key為type的一個(gè)object,引入redux-thunk時(shí)可為function以處理異步邏輯。
通過(guò)dispatch([action])的方式,發(fā)起一個(gè)動(dòng)作 => 中間件處理邏輯之后 => 調(diào)起reducer執(zhí)行對(duì)應(yīng)type的代碼,返回新的state。
dispatch
發(fā)起一個(gè)動(dòng)作,傳入action,該方法由store提供。
store.dispatch