
https://github.com/buckyroberts/React-Redux-Boilerplate
https://redux.js.org/docs/basics/Actions.html
https://www.youtube.com/watch?v=F59Z80p1Bcw&list=PL6gx4Cwl9DGBbSLZjvleMwldX8jGgXV6a&index=2
理解: Redux用一個Store來儲存所有的data,如果update的時候涉及某些component, 這些component里的data會由provider一起update了。


All Actions are automatically sent to all reducers!
這個function實際上叫actionCreator, 會創(chuàng)建一個action object return回去。這個action包含信息為 User-selected, payload為user。

假設(shè)這部分是我們一開始想要input的data。



Main Page. ? import其他所有functionality to here.
創(chuàng)建Store, 創(chuàng)建Logger. Store里有allReducers data.
render APP的內(nèi)容。

combineReducer這一步很關(guān)鍵,因為整個data store是包含一個Single Unit of Data. 有點像一個大包包住的class。這里的store 就交allReducers


這個部分有點Tricky,這里定義了一個Component應(yīng)該是什么樣子的。
這里實際上是Container部分,我們只選取Data Store里有用的部分顯示出來
bindActionCreators ? 讓某個component擁有某個action功能。
connect(mapStateToProps, matchDispatchToProps)(userList)
這個是讓userList這個component具備我們之前的action功能,讓component pay attention to state and action.
當(dāng)然我們在component里也需要寫onClick=... ?這個語法很Tricky, key也很Tricky。
Also 這個userList iterate users.

這里涉及react state和props的應(yīng)用。
connect mapStatetoProps to userDetails 這樣的話 ?userDetail這個Component里就有了一個叫user的property ?然后這個property 值設(shè)為 ?state.activeUser.
state.activeUser是從reducer/index.js里拿過來的,我不是很知道怎么做到的。。。也沒看到import? ? State指的是state of entire store. 我們之所以可以這么用是因為Container 屬于Component App里,被App 調(diào)用了。所以Provider Store 給App的話,也就相當(dāng)于Store給了Container. 這樣ReactJS access Redux Store里的data就可以通過connect(mapStateToProps)(reactComponent)的方法,把store里的data 以props的形式傳給component,然后display在js上。要對Store里的東西進行操作的話,connect(matchDispatchToProps)(component)
這時候,大家肯定很好奇reducers和之前定義的那些reducer.js 干嘛的。 reducer主要是用來在Action發(fā)生后,update store里的data用的。所以呢,我們會注意到mapStateToProps里的屬性其實有所不同for different component. 有的只涉及users,有的涉及activte_user. ?這樣呢, 比如調(diào)用傳入的matchDispatchToProps方法,aka, 某ActionCreator: selectUser的時候,就會有針對性的update 某種data, 如users or active_users 而不用update整個Store。

<Userlist />其實就是render 一個UserList Component

reducers:
自動?。?!Listen to actions, 當(dāng)Action being made, 它會用switch case判斷是哪種action,然后返回某種payload。

把這個import 進allReducers, 這樣集成一個Single Unit Reducers.?
這個Reducers里包含兩塊Memory 一個是users, 一個是all activateUsers.
