Object whose values correspond to different reducer functions.
A store enhancer is a higher-order function that composes a store creator to return a new, enhanced store creator. This is similar to middleware in that it allows you to alter the store interface in a composable way.
Store enhancers are much the same concept as higher-order components in React, which are also occasionally called “component enhancers”.
Because a store is not an instance, but rather a plain-object collection of
functions, copies can be easily created and modified without mutating the
original store. There is an example in compose
documentation
demonstrating that.
Most likely you'll never write a store enhancer, but you may use the one provided by the developer tools. It is what makes time travel possible without the app being aware it is happening. Amusingly, the Redux middleware implementation is itself a store enhancer.
Creates a Redux store that holds the state tree.
The only way to change the data in the store is to call dispatch()
on it.
There should only be a single store in your app. To specify how different
parts of the state tree respond to actions, you may combine several
reducers
into a single reducer function by using combineReducers
.
Creates a store enhancer that applies middleware to the dispatch method of the Redux store. This is handy for a variety of tasks, such as expressing asynchronous actions in a concise manner, or logging every action payload.
See redux-thunk
package as an example of the Redux middleware.
Because middleware is potentially asynchronous, this should be the first store enhancer in the composition chain.
Note that each middleware will be given the dispatch
and getState
functions as named arguments.
A store enhancer applying the middleware.
Turns an object whose values are action creators, into an object with the
same keys, but with every function wrapped into a dispatch
call so they
may be invoked directly. This is just a convenience method, as you can call
store.dispatch(MyActionCreators.doSomething())
yourself just fine.
For convenience, you can also pass a single function as the first argument, and get a function in return.
An object whose values are action creator functions.
One handy way to obtain it is to use ES6 import * as
syntax. You may
also pass a single function.
The dispatch
function available on your Redux store.
The object mimicking the original object, but with every action
creator wrapped into the dispatch
call. If you passed a function as
actionCreator
, the return value will also be a single function.
Turns an object whose values are different reducer functions, into a single reducer function. It will call every child reducer, and gather their results into a single state object, whose keys correspond to the keys of the passed reducer functions.
An object whose values correspond to different reducer
functions that need to be combined into one. One handy way to obtain it
is to use ES6 import * as reducers
syntax. The reducers may never
return undefined for any action. Instead, they should return their
initial state if the state passed to them was undefined, and the current
state for any unrecognized action.
A reducer function that invokes every reducer inside the passed object, and builds a state object with the same shape.
Composes single-argument functions from right to left. The rightmost function can take multiple arguments as it provides the signature for the resulting composite function.
R function obtained by composing the argument functions from right
to left. For example, compose(f, g, h)
is identical to doing
(...args) => f(g(h(...args)))
.
Generated using TypeDoc
A reducer (also called a reducing function) is a function that accepts an accumulation and a value and returns a new accumulation. They are used to reduce a collection of values down to a single value
Reducers are not unique to Redux—they are a fundamental concept in functional programming. Even most non-functional languages, like JavaScript, have a built-in API for reducing. In JavaScript, it's
Array.prototype.reduce()
.In Redux, the accumulated value is the state object, and the values being accumulated are actions. Reducers calculate a new state given the previous state and an action. They must be pure functions—functions that return the exact same output for given inputs. They should also be free of side-effects. This is what enables exciting features like hot reloading and time travel.
Reducers are the most important concept in Redux.
Do not put API calls into reducers.
S The type of state consumed and produced by this reducer.
A The type of actions the reducer can potentially respond to.