DEV Community

Discussion on: I can't understand Redux's `store.dispatch()`. Is it `store.takeAction()`?

Collapse
zeke profile image
Zeke Hernandez

Hey jianlin,

Interesting, I never took the time to think about this much.
But I think that "dispatch" refers not the programmer dispatching the action to the store, but rather the store dispatching the action to its reducer.

Collapse
sunflower profile image
sunflowerseed Author

I guess that can make sense...

Would we think of a store to be an object, that "has" a reducer (which is a function, not an object), which is a "rule book" that says how the state should change according to the action.

The getState() and subscribe() part are easier to understand.

If we consider all method names as an interface, it is like, it is between the object and the outside world. So dispatch sounds somewhat imperative and it is the internal working of the store. The outside world may not care about how the action is dispatched to the reducer. All the outside world cares is, I tell the store the action, and now change the state according to the rule book. From the standpoint of the outside world, it is:

  1. We create the store by providing it a "rule book" (the reducer)
  2. We send actions to it
  3. We get its state sometimes
  4. We want to be notified for change of state instead of always checking up on it.

so it translates to

  1. store = createStore(reducer)
  2. store.takeAction()
  3. store.state()
  4. store.addObserver()

But I guess it is one way to look at it.