Mosh Redux Part 3 (Your own Custom Store)

Before moving, we should familiarize ourselves with how Redux is written from scratch.

Previously, when we log the store, we see the public interface with three main functionality:

– getState
– dispatch
– subscribe

Let’s try to implement them.

My Store

We hide our store variable in myStore. It is private.

Dispatch

Our reducer function gets passed into our constructor.
So we add a reducer parameter.

We create a dispatch function. So by scope, we access the passed in reducer function, and pass in action, and state. Remember in our reducer, we always return the new state. So we reference our state to the returned state.

Notify Subscribers (UI components)

When the state of the store gets changed, we want to notify the UI components. Hence we need these UI components be able to subscribe to our store.