happypoulp / redux-tutorial

Learn how to use redux step by step
3.76k stars 546 forks source link

Explain why the second reducer recieves an array #47

Closed morenoh149 closed 9 years ago

morenoh149 commented 9 years ago

Could you explain why the initial reducer shows {} but the subsequent ones recieve [] https://github.com/happypoulp/redux-tutorial/blob/master/06_combine-reducers.js

gaearon commented 9 years ago

I think it's because state managed by userReducer is an object, but itemsReducer manages an array. (I agree explaining it beforehand would be a good idea.)

happypoulp commented 9 years ago

Yes it's actually because the initial state of the userReducer is an object {} (https://github.com/happypoulp/redux-tutorial/blob/master/06_combine-reducers.js#L53) but the initial state of the itemsReducer is an array [] (https://github.com/happypoulp/redux-tutorial/blob/master/06_combine-reducers.js#L62). I thought it would be a good way to demonstrate that the state held by Redux is really made of the slices of state that each reducer returns. I'll make it more clear :).

happypoulp commented 9 years ago

Done: https://github.com/happypoulp/redux-tutorial/commit/b04c8b8cc535b61b0d7008c7a2586a71e5f7431d , hope it's more clear now.