Set up Redux
This commit is contained in:
parent
b0334e4b66
commit
994649cfeb
@ -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
14
src/configureStore.js
Normal 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;
|
13
src/index.js
13
src/index.js
@ -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
1
src/reducers/index.js
Normal file
@ -0,0 +1 @@
|
||||
export * from './wsReducer';
|
13
src/reducers/wsReducer.js
Normal file
13
src/reducers/wsReducer.js
Normal 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;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user