From 7813213a89b44f0e72010085de238691d2474e02 Mon Sep 17 00:00:00 2001 From: DJCordhose Date: Thu, 1 Feb 2018 13:41:40 +0100 Subject: [PATCH] feat(redux): making redux configration scoped 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. --- packages/redux/README.md | 18 +++++++++--------- packages/redux/index.js | 6 ++++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/redux/README.md b/packages/redux/README.md index 2feb394c8..ec0caf8cf 100644 --- a/packages/redux/README.md +++ b/packages/redux/README.md @@ -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` @@ -49,8 +47,10 @@ const App = withMessage(props =>

{props.message}

); export default render( , createContext({ - reducers: { - [namespace]: (state = { message: 'Hello World!' }) => state, + redux: { + reducers: { + [namespace]: (state = { message: 'Hello World!' }) => state, + }, }, }) ); diff --git a/packages/redux/index.js b/packages/redux/index.js index 1a98a73d0..663779c9b 100644 --- a/packages/redux/index.js +++ b/packages/redux/index.js @@ -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'); @@ -91,6 +91,8 @@ exports.createContext = hopsReact.combineContexts( exports.reduxExtension = function(config) { return { context: exports.ReduxContext, - config: config, + config: { + redux: config, + }, }; };