dispatch/client/src/js/index.js

36 lines
1022 B
JavaScript
Raw Normal View History

2015-12-28 23:34:32 +00:00
import React from 'react';
import { render } from 'react-dom';
import { syncReduxAndRouter, replacePath } from 'redux-simple-router';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import configureStore from './store';
import createRoutes from './routes';
import Socket from './util/Socket';
import handleSocket from './socket';
import { createUUID } from './util';
import Root from './containers/Root';
const host = __DEV__ ? `${window.location.hostname}:1337` : window.location.host;
2015-12-28 23:34:32 +00:00
let uuid = localStorage.uuid;
let newUser = false;
if (!uuid) {
uuid = createUUID();
newUser = true;
}
const socket = new Socket(host, uuid);
2015-12-28 23:34:32 +00:00
const store = configureStore(socket);
handleSocket(socket, store);
2015-12-28 23:34:32 +00:00
const history = createBrowserHistory();
2015-12-28 23:34:32 +00:00
syncReduxAndRouter(history, store);
if (newUser) {
2015-12-28 23:34:32 +00:00
store.dispatch(replacePath('/connect'));
localStorage.uuid = uuid;
2015-12-28 23:34:32 +00:00
}
const routes = createRoutes();
2015-12-28 23:34:32 +00:00
render(<Root store={store} routes={routes} history={history} />, document.getElementById('root'));