-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Comments
-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. |
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. |
I agree we need to clarify the terminology, and in some cases find better naming. |
I wonder if there's a term that doesn't sound FP-ish but is not a “store” either. |
OTOH it's already called Redux so at least “reducer” sounds related. |
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 |
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. |
Especially because "reducer" is a precise description of what they actually are :) |
Updaters? Sounds descriptive + less snobbish than reducers. |
I like |
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? |
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. |
"Updater" implies that its mutative. "Reducer" makes it clear that you're returning a new state, not modifying the old one. |
That's a strong point in favor I think, may help with the issue about redux not working correctly with mutations |
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 :) |
I'm open to changing “Stores” to “Reducers” if this happens together with better docs. |
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. |
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. |
I like this although |
Yeah that's the one thing I don't really like, but the other methods makes sense: |
Now that I think of it, we're not really “dispatching” anything. |
Ok, so what we have so far are:
Maybe we can take a step back and re-think the naming? |
Maybe |
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. |
@gaearon I'll volunteer to lead this :) I have an outline started already. |
Thanks 👍 |
Thanks! 👍 👍 👍 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 ;) |
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.) |
I guess Flow is not a priority atm. |
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 |
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 Sounds like reduce to me. |
I'm for |
Take inspiration from Elm. https://github.com/evancz/elm-architecture-tutorial#the-basic-pattern The best word would be |
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.
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. |
State Transformer |
Try to avoid reinventing/rediscovering as much as possible. People have been calling it |
|
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. |
@vramana it is not a 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 |
I like to think of it as a projection (of an event log to a data structure). I like reduce or fold, it is well understood by different communities |
I much prefer Transformers to Reducers: it's clear what it means from the normal English usage of the word. |
Reducers. |
Reducer is accurate and has a precedent in vanilla JS. Not sure how that could be improved on. |
Reducers it shall be then. |
(Follow progress in #140) |
* “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.
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.
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.
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.
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.
`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)
Occasionally I find old discussions calling them “stores” and marvel at how ridiculously confusing it was in the hindsight. |
"state container"? |
Yes this was a good change :) |
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.
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.
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.
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.
The text was updated successfully, but these errors were encountered: