1. 16
    Redux: Implementing combineReducers() from Scratch
    4m 22s

Redux: Implementing combineReducers() from Scratch

InstructorDan Abramov

Share this video with your friends

Send Tweet

Learn how to build a reasonable approximation of the combineReducers() utility in 15 lines. No magic!

Sequoia McDowell
~ 8 years ago

I love that you explained what combineReducers does long-hand (writing it out explicitly) in the last video before introducing it here. That took the magic out of it and made it really easy to understand what's going on. Kudos!

mobility-team
~ 8 years ago

Great explanation, great content!

Enrique
~ 8 years ago

That was so meta, it made me go O_o

Brad Tittle
~ 7 years ago

Am I correct in saying the following:

Every event is dispatched to all of the reducers in combined reducers. If the action.type doesn't exist in the reducer it doesn't happen.

Or

If I wanted to have two different things happen with the same action, I can have to separate updates happen to the state. Let's say I am rolling the dice and tracking all rolls of the dice, I might keep a currentRoll running for display and a rollHistory for a fairness tracker. Since all actions pass through all reducers, I don't need to worry about managing which reducer is getting the action.

The more I look at this the more brilliant it is. The problem is attempting to pass it on to the next person.

I once got into an argument with someone about the ability of javascript to do multi dimensional arrays. He was fixated on the form array[ ][ ][ ][ ]. From what I can tell, he is correct that javascript doesn't do that. What is the difference between that and array[ { [ { [ ] } ] } ] and array [ ] [ ] [ ] [ ]. I think there are many differences. The question is, can I make the first one accomplish the tasks that the second one use to do. If n is small, it isn't that terrible. When n starts getting big, n^2 starts beating me up. But for most of the times I have run into multiple dimensions on arrays, the j, k and l usually stay small.

That is me attempting to say that communicating programming ideas to programmers can be challenging. Trying to communicate programming ideas to non programmers and have them actually hear what you said... That is how folks end up needing medication.

dan entous
~ 7 years ago

noticed that using combineReducers “from scratch” vs redux has a slight observable difference:

  • “from scratch” initialises by calling each reducer once
  • redux initialises by calling each reducer twice
  • then the store.createStore( todoApp ); calls each reducer again, once

why is that?

Enoh Barbu
~ 7 years ago
Aaron
~ 7 years ago

This (and this entire lesson) is really very good, thank you!