-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 1.17 KB
/
index.js
File metadata and controls
43 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from "react";
import Router, {Route, DefaultRoute} from "react-router";
import {createStore, applyMiddleware} from "redux";
import {Provider} from "react-redux";
import io from "socket.io-client";
import reducer from "./reducer";
import {setState} from "./action_creators";
import remoteActionMiddleware from "./remote_action_middleware";
import App from "./components/App";
import {VotingContainer} from "./components/Voting";
import {ResultsContainer} from "./components/Results";
const socket = io(`${location.protocol}//${location.hostname}:8090`);
const createStoreWithMiddleware = applyMiddleware(
remoteActionMiddleware(socket)
)(createStore);
const store = createStoreWithMiddleware(reducer);
socket.on("state", state =>
store.dispatch(setState(state)));
const routes = React.createElement(
Route,
{handler: App},
React.createElement(
DefaultRoute,
{handler: VotingContainer}
),
React.createElement(
Route,
{path:"/results", handler: ResultsContainer}
)
);
Router.run(routes, (Root) => {
React.render(
React.createElement(Provider, {store: store}, () => React.createElement(Root)),
document.getElementById("app")
);
})