reduxjs / redux

A JS library for predictable global state management
https://redux.js.org
MIT License
60.89k stars 15.27k forks source link

Proposal: Rename "stores" to "reducers" #137

Closed acdlite closed 9 years ago

acdlite commented 9 years ago

If I remember correctly, @gaearon, you said we'd make this change once Redux hit 500 stars. :)

It would also be nice to have a "Terminology" section of the docs so we can keep everyone on track. I've especially noticed that we currently use the word "dispatcher" to refer to at least three different things.

goatslacker commented 9 years ago

-1 the learning curve on this repo already feels steep. Let's not make it any steeper by introducing new terminology for new flux users.

Internally they can be called reducers, publicly keep them as stores so it's easier to grok.

acdlite commented 9 years ago

I honestly think it's more confusing the way it is now. Totally anecdotal, but I've had several people IRL get all messed up thinking about how a "store" could be stateless.

The main characteristics of "stores" in traditional Flux are that they 1) hold state, and 2) emit change events. Neither of which are true in Redux.

emmenko commented 9 years ago

I agree we need to clarify the terminology, and in some cases find better naming. I think as a first step there should be some JSDoc, then a terminology section would also help. In general we have to maintain a certain level of consistency.

gaearon commented 9 years ago

I wonder if there's a term that doesn't sound FP-ish but is not a “store” either. Domains?

gaearon commented 9 years ago

OTOH it's already called Redux so at least “reducer” sounds related.

leoasis commented 9 years ago

How about "step updates", or "steppers", which moves your state one step forward. I've seen this being used in Elm literature, having a function called step, update, or next

goatslacker commented 9 years ago

Domains contain node.js baggage.

They're not stores in how they function but you still put your state logic in there much like flux stores. They're state managers, like flux stores are supposed to be.

Reducers is fine if you're keen on changing its name though.

acdlite commented 9 years ago

Especially because "reducer" is a precise description of what they actually are :)

gaearon commented 9 years ago

Updaters? Sounds descriptive + less snobbish than reducers.

emmenko commented 9 years ago

I like reducer as well

acdlite commented 9 years ago

I guess I don't see why "reducer" is snobbish. Isn't it better to use the actual term than invent a new one that is less descriptive?

leoasis commented 9 years ago

I guess both may be valid, and it depends from which point of view you see it: a reducer of actions (into state), or an updater of state.

acdlite commented 9 years ago

"Updater" implies that its mutative. "Reducer" makes it clear that you're returning a new state, not modifying the old one.

leoasis commented 9 years ago

That's a strong point in favor I think, may help with the issue about redux not working correctly with mutations

acdlite commented 9 years ago

I do appreciate the need to keep Redux friendly to people who aren't familiar with FP, but we can solve that with better documentation. I like the current docs, but on first glance they're a bit overwhelming. A good docs site that foregrounds the familiar stuff (action creators, reducer logic) over the advanced stuff (middleware, hot reloading) would be very helpful.

And yet, judging from the rapid growth of the following here, we must be doing something right :)

gaearon commented 9 years ago

I'm open to changing “Stores” to “Reducers” if this happens together with better docs.

gaearon commented 9 years ago

The essential element is to preserve the “it's like Flux but better, don't worry” vibe. I don't want people to think it's similar to Reflux or something, which sounds like Flux but breaks some of its nice properties. I also don't want them to think they need to learn FP. As long as we can keep it so, I'm okay with this change.

acdlite commented 9 years ago

Suggestion I'm less sure about: If we rename the Redux class to Store (think about it: its two purposes are to hold state and emit change events) then the top-level API becomes:

const store = createStore(reducers);

<Provider store={store} />

This communicates the idea pretty well, I think. Reducers are where your store logic goes, but they are not stores themselves.

gaearon commented 9 years ago

I like this although store.dispatch feels wrong then.

acdlite commented 9 years ago

Yeah that's the one thing I don't really like, but the other methods makes sense: store.getState(), store.setState(), store.subscribe()

gaearon commented 9 years ago

Now that I think of it, we're not really “dispatching” anything. Ugh, naming is a rabbit hole.

emmenko commented 9 years ago

Ok, so what we have so far are:

Maybe we can take a step back and re-think the naming?

gaearon commented 9 years ago

Maybe store.dispatch is not too bad. We can just explain that instead of many Stores, we have a single Store, and you compose it from Reducers. No Stores = no need for a separate Dispatcher, so dispatch is available right on Store.

acdlite commented 9 years ago

@gaearon I agree.

@emmenko Good summary. Any terminology breakdown should distinguish between action creators and actions. It should also distinguish between the dispatcher or dispatch strategy, which encompasses middleware + reducers, as well as the dispatch method which triggers a dispatch cycle.

gaearon commented 9 years ago

Let's do this:

Anybody want to lead the new docs effort? It'll need some structuring: a glossary, a README, a simple “get-it-running” tutorial, and maybe an more in-depth “design decisions” guide.

acdlite commented 9 years ago

@gaearon I'll volunteer to lead this :) I have an outline started already.

gaearon commented 9 years ago

Thanks :+1:

emmenko commented 9 years ago

I'll volunteer to lead this

Thanks! :+1: :+1: :+1:

Personally, as a final outcome, I would really like to have an auto-generated website with:

...and as a nice-to-have feature:

But starting with markdown and jsdoc is of course a first step ;)

acdlite commented 9 years ago

Right, I think the first step is getting the docs written in Markdown form, then we can port them to a really nice docs site. :+1: for JSDoc, too. I'm going to take one final stab at https://github.com/gaearon/redux/pull/87 tonight but I'm not sure Flow annotations are worth it at this point unless we rid the codebase of function overloading. (Or unless someone teaches me how to properly type them without Flow complaining.)

emmenko commented 9 years ago

I guess Flow is not a priority atm.

jordangarcia commented 9 years ago

+1 for stores being called reducers.

I've not been fond of calling these more declarative, stateless things stores.

aaronjensen commented 9 years ago

I like the new name ideas. I'd also propose renaming Connector to something like Subscription. Connector is very generic, and while I get that it is connecting redux's state and dispatcher to its children, I think that a subscription is a better description of what is happening. It's a bit of a stretch that you get a dispatcher along w/ your subscription, but I think that's ok.

ianp commented 9 years ago

-1 for stores being called reducers, as a name it's not very intuitive for new users (at least those without a functional programming background). Maybe Updater or Transformer would be better, or Store Updater if we wanted to be more explicit about it.

gaearon commented 9 years ago

“Transformers” have been suggested quite a few times. It doesn't suggest mutable nature like Updaters, is more approachable than Reducers, and doesn't carry the “storage” connotation of Stores.

How do you like Transformers?

gcanti commented 9 years ago

+1 for Reducers

gaearon commented 9 years ago

As noted by @faassen on Twitter, a good argument for “reducers” is calling back to the project name. We have a chance to say “This is like Flux, but there is a single Store. Just like you can compose your app into React components, in Redux, you compose that Store out of Reducers. They are called Reducers because their signature matches function passed to [].reduce(): (state, action) => state. Bla bla bla”

ryanflorence commented 9 years ago

angular spread like wildfire and uses words like

Ignoring programming, transforming and reducing are different things. I'd pick the name that is the most accurate.

If they don't store data, don't call them stores.

Are you transforming from one form to another or are you reducing from many values to one?

Transformer => map Reducer => reduce

Sounds like reduce to me.

cef62 commented 9 years ago

I'm for reducers too! :+1:

staltz commented 9 years ago

Take inspiration from Elm. https://github.com/evancz/elm-architecture-tutorial#the-basic-pattern

The best word would be update. Store is nonsense, it has always been "Model". No need to reinvent the wheel or confuse people.

gaearon commented 9 years ago

My beef with calling them updaters is people might think they are supposed to be mutative. If the naming can help clarify non-mutative nature that would be a huge bonus.

Are you transforming from one form to another or are you reducing from many values to one?

I'm accumulating. “How an action turns a state into the next state.” Conceptually they're reducing over many actions from the initial (undefined) state, and memoization is just an optimization.

ajaybeniwal commented 9 years ago

State Transformer

staltz commented 9 years ago

Try to avoid reinventing/rediscovering as much as possible. People have been calling it reduce, scan, fold, and update.

lionelB commented 9 years ago

reducer seems to be accurate from a javascript perspective... Don't see the value to name it from a concept of another language, even if it's more accurate.

jonrh commented 9 years ago

Don't have a firm stand on what it should be but IMO it should be something that most accurately represents the type of computation. If it's an umfaliar word to most programmers then that can be offset by documentation.

leoasis commented 9 years ago

@vramana it is not a map, it is a reduce, since it takes the previously accumulated state and a new action and returns a new state.

If you had an array of all the actions of your app, you'd use this function to reduce it to the final app state:

function reducer(state, action) {
  // switch (action.type) ...
  // return state;
}
const finalState = allAppActions.reduce(reducer, initialState);

Now, what you really have is a stream of actions in time, which is conceptually the same as an array, but in time (you can reduce it into a stream of states).

slorber commented 9 years ago

I like to think of it as a projection (of an event log to a data structure). DB people used to call this "materialized views".

I like reduce or fold, it is well understood by different communities

ianp commented 9 years ago

I much prefer Transformers to Reducers: it's clear what it means from the normal English usage of the word.

ntkoso commented 9 years ago

Reducers. First, it's javascript library and javascript has [].reduce(reducer, initialState). Second, Redu(cer)x is already in library name. Third, https://blog.javascripting.com/2015/06/19/flux-no-more-stores-meet-reducer/ , other people and libraries will use 'reducers' term.

matthewwithanm commented 9 years ago

Reducer is accurate and has a precedent in vanilla JS. Not sure how that could be improved on.

gaearon commented 9 years ago

Reducers it shall be then.