Set up Redux

This commit is contained in:
Timothy Warren 2018-04-20 16:55:03 -04:00
parent b0334e4b66
commit 994649cfeb
5 changed files with 41 additions and 2 deletions

View File

@ -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 () {

14
src/configureStore.js Normal file
View File

@ -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;

View File

@ -1,4 +1,13 @@
import { App } from './App';
import { render } from 'inferno';
import { Provider } from 'inferno-redux';
render(<App />, document.getElementById('app'));
import configureStore from './configureStore';
import { App } from './App';
const store = configureStore();
render((
<Provider store={store}>
<App />
</Provider>
), document.getElementById('app'));

1
src/reducers/index.js Normal file
View File

@ -0,0 +1 @@
export * from './wsReducer';

13
src/reducers/wsReducer.js Normal file
View File

@ -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;
}
};