redux icon indicating copy to clipboard operation
redux copied to clipboard

Do we want to rename dispatch() and getState() before 1.0?

Open gaearon opened this issue 11 years ago • 60 comments

Bikeshedding thread here.

As part of 1.0 we can do some breaking changes we won't be able to do after 1.0. This includes bikeshedding on names.

I wanted this library to be a functional programming trojan horse for Flux people, which I think it succeeded at. Before we reach 1.0, we are able to drop some of the Flux naming baggage and find better names for whatever it does.

We're already getting rid of dispatcher and renaming stores to reducers. Do getState and dispatch still make sense?

Traditionally dispatch was called this way because in Flux an action really is dispatched across multiple Stores. In Redux, however, functional composition means that there is only one root reducer at the top. Do we really dispatch?

I've also heard some people are confused by getState as it sounds similar to React's setState and seems to imply some connection to React. In fact, Redux has nothing to do with React.

What if instead of { getState, dispatch, subscribe } we had... { read, perform, subscribe }? Let's bikeshed.

gaearon avatar Jul 07 '15 21:07 gaearon

push, pull, subscribe?

get, set, subscribe?

read, write, subscribe?

get, apply, subscribe?

or a more explicit: value(), reduce(), subscribe

goatslacker avatar Jul 07 '15 21:07 goatslacker

I think perform is way better than dispatch, as it captures what we are doing, performing an action. I'm not 100% sure about read - it's missing something for me Read what?. That might just be because I'm so used to getState by now.

johanneslumpe avatar Jul 07 '15 21:07 johanneslumpe

I don't mind value, apply or perform, subscribe

tappleby avatar Jul 07 '15 22:07 tappleby

I don't want symmetry (get/set, read/write) because they are asymmetric. One receives an action, another returns the state.

gaearon avatar Jul 07 '15 22:07 gaearon

I like this Trojan horse idea.

To me, read sounds like some action is being taken rather than just accessing some existing value.

Maybe valueOf?

dispatch -> perform sounds pretty good. Can't think of anything better.

mindjuice avatar Jul 07 '15 22:07 mindjuice

perform is way too general. Performing what? dispatch may not be ideal, but it's at least somewhat specific.

acdlite avatar Jul 07 '15 22:07 acdlite

dispatch was called this way because in Flux an action really is dispatched across multiple Stores

Even with a single reducer, in practice the same action is still being handled by many different sub-reducers. I think dispatch() still kind of fits, but I agree we should try to find something better.

acdlite avatar Jul 07 '15 22:07 acdlite

Clojure uses send to send actions to agents. (http://clojure.org/agents)

mindjuice avatar Jul 07 '15 22:07 mindjuice

Is perform(action) really more general than dispatch(action)?

If we throw away the Flux association (which is misleading anyway b/c there is no dispatching under the hood) they sound equally generic to me.

gaearon avatar Jul 07 '15 22:07 gaearon

I can perform a task, or a symphony, or a lobotomy. Dispatch is much narrower.

acdlite avatar Jul 07 '15 22:07 acdlite

Transducers have step(), which is technically a reducer itself...

type Step<X, Y> = (acc: X, val: Y) => X

...but still conceptually related

acdlite avatar Jul 07 '15 22:07 acdlite

I like send, but I think if we do get rid of dispatch, its replacement needs to be significantly better, since we're switching it for a term that people already understand. I'm not sure if send crosses that threshold.

Also send and dispatch are basically synonyms.

acdlite avatar Jul 07 '15 22:07 acdlite

Could be another way: { getState, performAction, subscribe }. Too verbose?

gaearon avatar Jul 07 '15 22:07 gaearon

I kinda think so, and I don't see what it gives us versus dispatch. It's also an imperative phrase (in the English sense, not the programming sense*) which implies that an action has yet to occur, whereas action objects are representations of things that have already happened.

*EDIT: although come to think of it, in the programming sense too *EDIT2: that's not really fair, though, because essentially all function names are imperative :)

acdlite avatar Jul 07 '15 22:07 acdlite

For context, here are the dictionary definitions (I just took the first entry from Google):

  • dispatch – send off to a destination or for a purpose.
  • perform – carry out, accomplish, or fulfill (an action, task, or function)
  • send – cause to go or be taken to a particular destination; arrange for the delivery of, especially by mail

dispatch still fits the closest, IMO. It has the "fire and forget" connotation.

acdlite avatar Jul 07 '15 22:07 acdlite

Do you need the get? How about just state.

const { counter } = redux.state();

mindjuice avatar Jul 07 '15 22:07 mindjuice

@mindjuice That looks like a direct reference to an object, whereas getState() is clearly an accessor.

acdlite avatar Jul 07 '15 22:07 acdlite

@acdlite Sorry, I have no idea what you mean by that! Can you elaborate?

mindjuice avatar Jul 07 '15 22:07 mindjuice

@mindjuice Sure :) redux.state looks like you could use it like this:

redux.state.todos // wrong

whereas getState() is clearly a function

redux.getState().todos

acdlite avatar Jul 07 '15 22:07 acdlite

I see what you mean, but did you miss the parentheses after state() in my example line? It is a function.

const { counter } = redux.state();

mindjuice avatar Jul 07 '15 22:07 mindjuice