Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
acdlite opened this Issue Jun 18, 2015 · 54 comments

Comments

@acdlite
Copy link
Collaborator

commented Jun 18, 2015

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

This comment has been minimized.

Copy link

commented Jun 18, 2015

-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

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

@leoasis

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

This comment has been minimized.

Copy link

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

Updaters? Sounds descriptive + less snobbish than reducers.

@emmenko

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

I like reducer as well

@acdlite

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

@leoasis

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

@acdlite

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

I like this although store.dispatch feels wrong then.

@acdlite

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

@emmenko

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

Ok, so what we have so far are:

  • action (creators)
  • (store) reducer
  • middleware functions
  • callback (listener) functions
  • something that triggers the functions call chain (called dispatcher)
  • something that holds the mutable state (with setters and getters)

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

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

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

@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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

Let's do this:

  • Rename Stores to Reducers
  • Rename the “Redux instance” to Store as per #137 (comment)
  • Explain that if you squint at traditional Flux Stores, you'll see Reducers trapped in them

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

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

Thanks 👍

@emmenko

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

I'll volunteer to lead this

Thanks! 👍 👍 👍

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

  • getting started
  • tutorials
  • live examples

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

  • generated documentation a-la docco (e.g.: like jasmine) so that the source code is clearly explained

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

@acdlite

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 18, 2015

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. 👍 for JSDoc, too. I'm going to take one final stab at #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

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2015

I guess Flow is not a priority atm.

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

“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

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

+1 for Reducers

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

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

This comment has been minimized.

Copy link

commented Jun 22, 2015

angular spread like wildfire and uses words like

  • directive
  • isolate
  • transclude

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

This comment has been minimized.

Copy link

commented Jun 22, 2015

I'm for reducers too! 👍

@staltz

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

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

This comment has been minimized.

Copy link

commented Jun 22, 2015

State Transformer

@staltz

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

@lionelB

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

@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

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

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

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

@ntkoso

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

This comment has been minimized.

Copy link

commented Jun 22, 2015

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

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

Reducers it shall be then.

@gaearon gaearon closed this Jun 22, 2015

@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2015

(Follow progress in #140)

gaearon added a commit that referenced this issue Jun 30, 2015

Breaking API changes for 1.0
* “Stateless Stores” are now called reducers. (#137 (comment))
* The “Redux instance” is now called “The Store”. (#137 (comment))
* The dispatcher is removed completely. (#166 (comment))

* <s>`composeStores`</s> is now `composeReducers`.
* <s>`createDispatcher`</s> is gone.
* <s>`createRedux`</s> is now `createStore`.
* `<Provider>` now accepts `store` prop instead of <s>`redux`</s>.
* The new `createStore` signature is `createStore(reducer: Function | Object, initialState: any, middlewares: Array | ({ getState, dispatch }) => Array)`.
* If the first argument to `createStore` is an object, `composeReducers` is automatically applied to it.
* The “smart” middleware signature changed. It now accepts an object instead of a single `getState` function. The `dispatch` function lets you “recurse” the middleware chain and is useful for async: #113 (comment).
* The `dispatch` provided by the default thunk middleware now walks the whole middleware chain.
* It is enforced now that Actions have to be plain object. Use middleware for transforming anything else into the actions.

* The object in React context is renamed from <s>`redux`</s> to `store`.
* Some tests are rewritten for clarity, focus and edge cases.
* Redux in examples is now aliased to the source code for easier work on master.

gaearon added a commit that referenced this issue Jun 30, 2015

Breaking API changes for 1.0
Naming:

* “Stateless Stores” are now called reducers. (#137 (comment))
* The “Redux instance” is now called “The Store”. (#137 (comment))
* The dispatcher is removed completely. (#166 (comment))

API changes:

* <s>`composeStores`</s> is now `composeReducers`.
* <s>`createDispatcher`</s> is gone.
* <s>`createRedux`</s> is now `createStore`.
* `<Provider>` now accepts `store` prop instead of <s>`redux`</s>.
* The new `createStore` signature is `createStore(reducer: Function | Object, initialState: any, middlewares: Array | ({ getState, dispatch }) => Array)`.
* If the first argument to `createStore` is an object, `composeReducers` is automatically applied to it.
* The “smart” middleware signature changed. It now accepts an object instead of a single `getState` function. The `dispatch` function lets you “recurse” the middleware chain and is useful for async: #113 (comment).
* The `dispatch` provided by the default thunk middleware now walks the whole middleware chain.
* It is enforced now that Actions have to be plain object. Use middleware for transforming anything else into the actions.

Internal changes:

* The object in React context is renamed from <s>`redux`</s> to `store`.
* Some tests are rewritten for clarity, focus and edge cases.
* Redux in examples is now aliased to the source code for easier work on master.

gaearon added a commit that referenced this issue Jun 30, 2015

Breaking API changes for 1.0
Naming:

* “Stateless Stores” are now called reducers. (#137 (comment))
* The “Redux instance” is now called “The Store”. (#137 (comment))
* The dispatcher is removed completely. (#166 (comment))

API changes:

* <s>`composeStores`</s> is now `composeReducers`.
* <s>`createDispatcher`</s> is gone.
* <s>`createRedux`</s> is now `createStore`.
* `<Provider>` now accepts `store` prop instead of <s>`redux`</s>.
* The new `createStore` signature is `createStore(reducer: Function | Object, initialState: any, middlewares: Array | ({ getState, dispatch }) => Array)`.
* If the first argument to `createStore` is an object, `composeReducers` is automatically applied to it.
* The “smart” middleware signature changed. It now accepts an object instead of a single `getState` function. The `dispatch` function lets you “recurse” the middleware chain and is useful for async: #113 (comment).
* The `dispatch` provided by the default thunk middleware now walks the whole middleware chain.
* It is enforced now that raw Actions at the end of the middleware chain have to be plain objects.

Internal changes:

* The object in React context is renamed from <s>`redux`</s> to `store`.
* Some tests are rewritten for clarity, focus and edge cases.
* Redux in examples is now aliased to the source code for easier work on master.

gaearon added a commit that referenced this issue Jun 30, 2015

Breaking API changes for 1.0
Naming:

* “Stateless Stores” are now called reducers. (#137 (comment))
* The “Redux instance” is now called “The Store”. (#137 (comment))
* The dispatcher is removed completely. (#166 (comment))

API changes:

* <s>`composeStores`</s> is now `composeReducers`.
* <s>`createDispatcher`</s> is gone.
* <s>`createRedux`</s> is now `createStore`.
* `<Provider>` now accepts `store` prop instead of <s>`redux`</s>.
* The new `createStore` signature is `createStore(reducer: Function | Object, initialState: any, middlewares: Array | ({ getState, dispatch }) => Array)`.
* If the first argument to `createStore` is an object, `composeReducers` is automatically applied to it.
* The “smart” middleware signature changed. It now accepts an object instead of a single `getState` function. The `dispatch` function lets you “recurse” the middleware chain and is useful for async: #113 (comment).

Correctness changes:

* The `dispatch` provided by the default thunk middleware now walks the whole middleware chain.
* It is enforced now that raw Actions at the end of the middleware chain have to be plain objects.
* Nested dispatches are now handled gracefully. (#110)

Internal changes:

* The object in React context is renamed from <s>`redux`</s> to `store`.
* Some tests are rewritten for clarity, focus and edge cases.
* Redux in examples is now aliased to the source code for easier work on master.

gaearon added a commit that referenced this issue Jun 30, 2015

Breaking API changes for 1.0
Naming:

* “Stateless Stores” are now called reducers. (#137 (comment))
* The “Redux instance” is now called “The Store”. (#137 (comment))
* The dispatcher is removed completely. (#166 (comment))

API changes:

* <s>`composeStores`</s> is now `composeReducers`.
* <s>`createDispatcher`</s> is gone.
* <s>`createRedux`</s> is now `createStore`.
* `<Provider>` now accepts `store` prop instead of <s>`redux`</s>.
* The new `createStore` signature is `createStore(reducer: Function | Object, initialState: any, middlewares: Array | ({ getState, dispatch }) => Array)`.
* If the first argument to `createStore` is an object, `composeReducers` is automatically applied to it.
* The “smart” middleware signature changed. It now accepts an object instead of a single `getState` function. The `dispatch` function lets you “recurse” the middleware chain and is useful for async: #113 (comment).

Correctness changes:

* The `dispatch` provided by the default thunk middleware now walks the whole middleware chain.
* It is enforced now that raw Actions at the end of the middleware chain have to be plain objects.
* Nested dispatches are now handled gracefully. (#110)

Internal changes:

* The object in React context is renamed from <s>`redux`</s> to `store`.
* Some tests are rewritten for clarity, focus and edge cases.
* Redux in examples is now aliased to the source code for easier work on master.

acstll added a commit to acstll/chopped-redux that referenced this issue Aug 7, 2015

Rename `reducer` to `update`
`update` is a much simpler term and it's as accurate as `reducer`.
I don't believe `update` implies mutation.

reduxjs/redux#137 (comment)
reduxjs/redux#137 (comment)
@gaearon

This comment has been minimized.

Copy link
Contributor

commented Jan 26, 2016

Occasionally I find old discussions calling them “stores” and marvel at how ridiculously confusing it was in the hindsight.

@kof

This comment has been minimized.

Copy link

commented Jan 26, 2016

"state container"?

@goatslacker

This comment has been minimized.

Copy link

commented Jan 26, 2016

Yes this was a good change :)

pandafulmanda pushed a commit to pandafulmanda/testing-example that referenced this issue Aug 2, 2018

Breaking API changes for 1.0
Naming:

* “Stateless Stores” are now called reducers. (reduxjs/redux#137 (comment))
* The “Redux instance” is now called “The Store”. (reduxjs/redux#137 (comment))
* The dispatcher is removed completely. (reduxjs/redux#166 (comment))

API changes:

* <s>`composeStores`</s> is now `composeReducers`.
* <s>`createDispatcher`</s> is gone.
* <s>`createRedux`</s> is now `createStore`.
* `<Provider>` now accepts `store` prop instead of <s>`redux`</s>.
* The new `createStore` signature is `createStore(reducer: Function | Object, initialState: any, middlewares: Array | ({ getState, dispatch }) => Array)`.
* If the first argument to `createStore` is an object, `composeReducers` is automatically applied to it.
* The “smart” middleware signature changed. It now accepts an object instead of a single `getState` function. The `dispatch` function lets you “recurse” the middleware chain and is useful for async: reduxjs/redux#113 (comment).

Correctness changes:

* The `dispatch` provided by the default thunk middleware now walks the whole middleware chain.
* It is enforced now that raw Actions at the end of the middleware chain have to be plain objects.
* Nested dispatches are now handled gracefully. (reduxjs/redux#110)

Internal changes:

* The object in React context is renamed from <s>`redux`</s> to `store`.
* Some tests are rewritten for clarity, focus and edge cases.
* Redux in examples is now aliased to the source code for easier work on master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.