Skip to content

Commit

Permalink
Fix Redux exports (#243)
Browse files Browse the repository at this point in the history
* Export all types and methods from Redux

* Update "Other Exports" and "createSlice" docs
  • Loading branch information
markerikson authored Nov 2, 2019
1 parent b868b43 commit f9a5636
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
8 changes: 5 additions & 3 deletions docs/api/createSlice.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ and automatically generates action creators and action types that correspond to
```ts
function createSlice({
// An object of "case reducers". Key names will be used to generate actions.
reducers: Object<string, ReducerFunction>
reducers: Object<string, ReducerFunction | ReducerAndPrepareObject>
// The initial state for the reducer
initialState: any,
// A name, used in action types
Expand All @@ -40,6 +40,10 @@ descriptive names.
This object will be passed to [`createReducer`](./createReducer.md), so the reducers may safely "mutate" the
state they are given.

#### Customizing Generated Action Creators

If you need to customize the creation of the payload value of an action creator by means of a [`prepare callback`](./createAction.md#using-prepare-callbacks-to-customize-action-contents), the value of the appropriate field of the `reducers` argument object should be an object instead of a function. This object must contain two properties: `reducer` and `prepare`. The value of the `reducer` field should be the case reducer function while the value of the `prepare` field should be the prepare callback function.

### `initialState`

The initial state value for this slice of state.
Expand Down Expand Up @@ -82,8 +86,6 @@ to force the TS compiler to accept the computed property.)
Each function defined in the `reducers` argument will have a corresponding action creator generated using [`createAction`](./createAction.md)
and included in the result's `actions` field using the same function name.

If you need to customize the creation of the payload value of an action creator by means of a [`prepare callback`](./createAction.md#using-prepare-callbacks-to-customize-action-contents), the value of the appropriate field of the `reducers` argument object should be an object instead of a function. This object must contain two properties: reducer and prepare. The value of the reducer field should be the case reducer function while the value of the prepare field should be the prepare callback function.

The generated `reducer` function is suitable for passing to the Redux `combineReducers` function as a "slice reducer".

You may want to consider destructuring the action creators and exporting them individually, for ease of searching
Expand Down
18 changes: 15 additions & 3 deletions docs/api/otherExports.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,25 @@ function isPlain(val) {

### `createNextState`

The default immutable update function from the [`immer` library](https://github.com/mweststrate/immer#api), re-exported here as `createNextState` (also commonly referred to as `produce`)
The default immutable update function from the [`immer` library](https://immerjs.github.io/immer/), re-exported here as `createNextState` (also commonly referred to as [`produce`](https://immerjs.github.io/immer/docs/produce))

### `combineReducers`

Redux's `combineReducers`, re-exported for convenience. While `configureStore` calls this internally, you may wish to call it yourself to compose multiple levels of slice reducers.
Redux's [`combineReducers`](https://redux.js.org/api/combinereducers), re-exported for convenience. While `configureStore` calls this internally, you may wish to call it yourself to compose multiple levels of slice reducers.

### `compose`

Redux's `compose`. It composes functions from right to left.
Redux's [`compose`](https://redux.js.org/api/compose). It composes functions from right to left.
This is a functional programming utility. You might want to use it to apply several store custom enhancers/ functions in a row.

### `bindActionCreators`

Redux's [`bindActionCreators`](https://redux.js.org/api/bindactioncreators). It wraps action creators with `dispatch()` so that they dispatch immediately when called.

### `createStore`

Redux's [`createStore`](https://redux.js.org/api/createstore). You should not need to use this directly.

### `applyMiddleware`

Redux's [`applyMiddleware`](https://redux.js.org/api/applymiddleware). You should not need to use this directly.
12 changes: 1 addition & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
export {
Action,
ActionCreator,
AnyAction,
Middleware,
Reducer,
Store,
StoreEnhancer,
combineReducers,
compose
} from 'redux'
export * from 'redux'
export { default as createNextState } from 'immer'
export { createSelector } from 'reselect'

Expand Down

0 comments on commit f9a5636

Please sign in to comment.