From 994649cfeb3f0de5e8de762068d887b751e7ccfc Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 20 Apr 2018 16:55:03 -0400 Subject: [PATCH] Set up Redux --- src/App.js | 2 ++ src/configureStore.js | 14 ++++++++++++++ src/index.js | 13 +++++++++++-- src/reducers/index.js | 1 + src/reducers/wsReducer.js | 13 +++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/configureStore.js create mode 100644 src/reducers/index.js create mode 100644 src/reducers/wsReducer.js diff --git a/src/App.js b/src/App.js index c25808a..be13f91 100644 --- a/src/App.js +++ b/src/App.js @@ -31,6 +31,8 @@ export class App extends Component { window.clientWS.addEventListener('open', this.onWebSocketOpen); window.clientWS.addEventListener('message', console); window.clientWS.addEventListener('close', this.onWebSocketClose); + + console.info(this.context); } componentWillUnmount () { diff --git a/src/configureStore.js b/src/configureStore.js new file mode 100644 index 0000000..04acba5 --- /dev/null +++ b/src/configureStore.js @@ -0,0 +1,14 @@ +/** + * Redux setup + */ +import { combineReducers, createStore } from 'redux'; + +import * as reducers from './reducers'; + +const configureStore = (defaultState = {}) => { + return createStore(combineReducers({ + ...reducers, + }), defaultState); +}; + +export default configureStore; diff --git a/src/index.js b/src/index.js index 36e3afc..94afb66 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,13 @@ -import { App } from './App'; import { render } from 'inferno'; +import { Provider } from 'inferno-redux'; -render(, document.getElementById('app')); +import configureStore from './configureStore'; +import { App } from './App'; + +const store = configureStore(); + +render(( + + + +), document.getElementById('app')); diff --git a/src/reducers/index.js b/src/reducers/index.js new file mode 100644 index 0000000..3d6b493 --- /dev/null +++ b/src/reducers/index.js @@ -0,0 +1 @@ +export * from './wsReducer'; diff --git a/src/reducers/wsReducer.js b/src/reducers/wsReducer.js new file mode 100644 index 0000000..6d359d2 --- /dev/null +++ b/src/reducers/wsReducer.js @@ -0,0 +1,13 @@ +/** + * Reducer for websocket-based actions + * + * @param {object} state + * @param {object} action + * @return {object} newState + */ +export const wsReducer = (state = {}, action) => { + switch (action.type) { + default: + return state; + } +};