DEV Community

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

Collapse
 
sunflower profile image
sunflowerseed

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.