dispatch/client/src/js/index.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-12-28 23:34:32 +00:00
import React from 'react';
import { render } from 'react-dom';
2016-01-15 19:56:03 +00:00
import { browserHistory } from 'react-router';
2016-02-04 02:35:50 +00:00
import { routeActions } from 'react-router-redux';
2015-12-28 23:34:32 +00:00
import configureStore from './store';
import createRoutes from './routes';
import Socket from './util/Socket';
import handleSocket from './socket';
import Root from './containers/Root';
const host = __DEV__ ? `${window.location.hostname}:1337` : window.location.host;
const socket = new Socket(host);
2015-12-28 23:34:32 +00:00
2016-01-15 19:56:03 +00:00
const store = configureStore(socket, browserHistory);
2016-02-03 18:42:07 +00:00
const env = JSON.parse(document.getElementById('env').innerHTML);
// TODO: Handle this properly
window.__ENV__ = {
defaults: env.defaults
};
if (env.servers) {
store.dispatch({
type: 'SOCKET_SERVERS',
2016-02-03 18:42:07 +00:00
data: env.servers
});
} else {
store.dispatch(routeActions.replace('/connect'));
}
2016-02-03 18:42:07 +00:00
if (env.channels) {
store.dispatch({
type: 'SOCKET_CHANNELS',
2016-02-03 18:42:07 +00:00
data: env.channels
});
}
2016-02-03 18:42:07 +00:00
if (env.users) {
store.dispatch({
type: 'SOCKET_USERS',
2016-02-03 18:42:07 +00:00
...env.users
});
}
2016-01-15 19:56:03 +00:00
handleSocket(socket, store);
2015-12-28 23:34:32 +00:00
const routes = createRoutes();
2015-12-28 23:34:32 +00:00
2016-01-15 19:56:03 +00:00
render(
<Root store={store} routes={routes} history={browserHistory} />,
document.getElementById('root')
);