1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/assets/js/app.js
2018-03-12 11:28:21 -04:00

54 lines
1.1 KiB
JavaScript

"use strict";
import "babel-polyfill";
import "phoenix_html";
import React from "react";
import ReactDOM from "react-dom";
import { createStore } from "redux";
import { Provider } from "react-redux";
import Channel from "./services/channel";
import chessBoardReducer from "./reducers/chess-board";
import { setGameId } from "./store/actions";
const store = createStore(chessBoardReducer);
class App extends React.Component {
componentWillMount() {
const { gameId, store } = this.props;
store.dispatch(setGameId(gameId));
this.channel = new Channel(store, gameId);
}
sendMove(gameId, move) {
this.channel.sendMove(move);
}
render() {
const { store, gameId } = this.props;
return (
<ChessBoard
gameId={gameId}
store={store}
sendMove={this.sendMove.bind(this)}
/>
);
}
}
const container = document.getElementById("app");
if (container != undefined) {
const gameId = container.getAttribute("data-game-id");
ReactDOM.render(
<App store={store} gameId={gameId} />,
container
);
}