From f8f1413dda4f2ac37223354ad933b073fe2bfd95 Mon Sep 17 00:00:00 2001 From: Konstantin Tarkus Date: Tue, 27 Sep 2016 09:56:21 +0300 Subject: [PATCH] A bare minimum Redux integration --- package.json | 3 +++ src/actions/README.md | 3 +++ src/client.js | 4 ++++ src/components/App.js | 7 +++++++ src/components/Html.js | 9 ++++++++- src/core/createStore.js | 13 +++++++++++++ src/reducers/README.md | 3 +++ src/reducers/index.js | 16 ++++++++++++++++ src/reducers/user.js | 15 +++++++++++++++ src/server.js | 7 +++++++ 10 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/actions/README.md create mode 100644 src/core/createStore.js create mode 100644 src/reducers/README.md create mode 100644 src/reducers/index.js create mode 100644 src/reducers/user.js diff --git a/package.json b/package.json index 27999ff9a..d985848b6 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,10 @@ "query-string": "4.2.3", "react": "15.3.2", "react-dom": "15.3.2", + "react-redux": "4.4.5", + "redux": "3.6.0", "sequelize": "3.24.5", + "serialize-javascript": "1.3.0", "source-map-support": "0.4.5", "sqlite3": "3.1.6", "universal-router": "2.0.0", diff --git a/src/actions/README.md b/src/actions/README.md new file mode 100644 index 000000000..c4daa622d --- /dev/null +++ b/src/actions/README.md @@ -0,0 +1,3 @@ +## Redux Actions + +For more information visit http://redux.js.org/docs/basics/Actions.html diff --git a/src/client.js b/src/client.js index 867a7563e..1b6155f3d 100644 --- a/src/client.js +++ b/src/client.js @@ -16,6 +16,7 @@ import queryString from 'query-string'; import { createPath } from 'history/PathUtils'; import history from './core/history'; import App from './components/App'; +import createStore from './core/createStore'; import { ErrorReporter, deepForceUpdate } from './core/devUtils'; // Global (context) variables that can be easily accessed from any React component @@ -28,6 +29,9 @@ const context = { const removeCss = styles.map(x => x._insertCss()); return () => { removeCss.forEach(f => f()); }; }, + // Initialize a new Redux store + // http://redux.js.org/docs/basics/UsageWithReact.html + store: createStore(window.APP_STATE), }; function updateTag(tagName, keyName, keyValue, attrName, attrValue) { diff --git a/src/components/App.js b/src/components/App.js index d5f7a172f..5c3614b32 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -13,6 +13,13 @@ const ContextType = { // Enables critical path CSS rendering // https://github.com/kriasoft/isomorphic-style-loader insertCss: PropTypes.func.isRequired, + // Integrate Redux + // http://redux.js.org/docs/basics/UsageWithReact.html + store: PropTypes.shape({ + subscribe: PropTypes.func.isRequired, + dispatch: PropTypes.func.isRequired, + getState: PropTypes.func.isRequired, + }).isRequired, }; /** diff --git a/src/components/Html.js b/src/components/Html.js index 080606639..c7b2db35e 100644 --- a/src/components/Html.js +++ b/src/components/Html.js @@ -8,9 +8,10 @@ */ import React, { PropTypes } from 'react'; +import serialize from 'serialize-javascript'; import { analytics } from '../config'; -function Html({ title, description, style, script, chunk, children }) { +function Html({ title, description, style, script, state, chunk, children }) { return ( @@ -24,6 +25,11 @@ function Html({ title, description, style, script, chunk, children }) {
+ {state &&