Reducer Composition Revisited

In this lesson, we will refactor our reducers into a more generic format. This will help us combine them in the combinedReducer (Implementation below).

We'll cover the following...

Let me take a step back and explain how reducer composition works again. This time, from a different perspective.

Consider the javascript object below:

Press + to interact
const state = {
user: "me",
messages: "hello",
contacts: ["no one", "khalid"],
activeUserId: 1234
}

Now, assume that instead of having the values of the keys hardcoded, we wanted it to be represented by function calls. That may look like this:

Press + to interact
const state = {
user: getUser(),
messages: getMsg(),
contacts: getContacts(),
activeUserId: getID()
}

This assumes that getUser() will also return the previous value, “me”. The same goes for the other replaced functions.

Still following?

Now, ...