Skip to content

Commit

Permalink
feat(redux): making redux configration scoped
Browse files Browse the repository at this point in the history
Configuration in redux#createContext is now scoped under namespace "redux". At the same time silently deprecating the previous unscoped version by deleting it from documentation.
  • Loading branch information
DJCordhose authored and dmbch committed Feb 2, 2018
1 parent 4df6cb2 commit 7813213
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 9 additions & 9 deletions packages/redux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ npm install --save hops-redux react react-redux redux redux-thunk

## `createContext(options)`

`createContext()` is hops-redux's main export. Of course, it is based on the implementation in [hops-react](https://github.com/xing/hops/tree/master/packages/react#createcontextoptions), but takes additional `reducers` and `middlewares` options.
`createContext()` is hops-redux's main export. Additional to the config options of [hops-react's createContext](https://github.com/xing/hops/tree/master/packages/react#createcontextoptions) it takes additional `reducers` and `middlewares` options under the `redux` namespace.

| Field | Type | Default | Description |
| ----------- | -------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| mountpoint | String | `'#main'` | querySelector identifying the root DOM node |
| template | Function | `defaultTemplate` | template function supporting all React Helmet and hops-react features |
| reducers | Object | `{}` | object literal containing reducers to be passed to Redux's [`combineReducers()`](http://redux.js.org/docs/api/combineReducers.html) |
| middlewares | Array | `[ReduxThunkMiddleware]` | array specifying the redux middlewares to apply. Uses [redux-thunk](https://github.com/gaearon/redux-thunk) as default. When middlewares is specified redux-thunk will not be included by default and needs to be added as well if needed. |
| Field | Type | Default | Description |
| ----------------- | ------ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| redux.reducers | Object | `{}` | object literal containing reducers to be passed to Redux's [`combineReducers()`](http://redux.js.org/docs/api/combineReducers.html) |
| redux.middlewares | Array | `[ReduxThunkMiddleware]` | array specifying the redux middlewares to apply. Uses [redux-thunk](https://github.com/gaearon/redux-thunk) as default. When middlewares is specified redux-thunk will not be included by default and needs to be added as well if needed. |

## `ReduxContext`

Expand All @@ -49,8 +47,10 @@ const App = withMessage(props => <h1>{props.message}</h1>);
export default render(
<App />,
createContext({
reducers: {
[namespace]: (state = { message: 'Hello World!' }) => state,
redux: {
reducers: {
[namespace]: (state = { message: 'Hello World!' }) => state,
},
},
})
);
Expand Down
6 changes: 4 additions & 2 deletions packages/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var REDUX_STATE = 'REDUX_STATE';

exports.ReduxContext = function(options) {
this.reducers = {};
options = options || {};
options = options.redux || options || {};
this.middlewares = options.middlewares || [ReduxThunkMiddleware];
if (!Array.isArray(this.middlewares)) {
throw new Error('middlewares needs to be an array');
Expand Down Expand Up @@ -91,6 +91,8 @@ exports.createContext = hopsReact.combineContexts(
exports.reduxExtension = function(config) {
return {
context: exports.ReduxContext,
config: config,
config: {
redux: config,
},
};
};

0 comments on commit 7813213

Please sign in to comment.