Skip to content

Commit 3c85a5d

Browse files
author
hiukim
committedAug 8, 2016
part 1 - data sync
0 parents  commit 3c85a5d

16 files changed

+247
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

‎.meteor/.finished-upgraders

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file contains information which helps Meteor properly upgrade your
2+
# app when you run 'meteor update'. You should check it into version control
3+
# with your project.
4+
5+
notices-for-0.9.0
6+
notices-for-0.9.1
7+
0.9.4-platform-file
8+
notices-for-facebook-graph-api-2
9+
1.2.0-standard-minifiers-package
10+
1.2.0-meteor-platform-split
11+
1.2.0-cordova-changes
12+
1.2.0-breaking-changes
13+
1.3.0-split-minifiers-package
14+
1.4.0-remove-old-dev-bundle-link

‎.meteor/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local

‎.meteor/.id

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file contains a token that is unique to your project.
2+
# Check it into your repository along with the rest of this directory.
3+
# It can be used for purposes such as:
4+
# - ensuring you don't accidentally deploy one app on top of another
5+
# - providing package authors with aggregated statistics
6+
7+
7m234ynbgevk1q3x9sj

‎.meteor/packages

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Meteor packages used by this project, one per line.
2+
# Check this file (and the other files in this directory) into your repository.
3+
#
4+
# 'meteor add' and 'meteor remove' will edit this file for you,
5+
# but you can also edit it by hand.
6+
7+
meteor-base@1.0.4 # Packages every Meteor app needs to have
8+
mobile-experience@1.0.4 # Packages for a great mobile UX
9+
mongo@1.1.10 # The database Meteor supports right now
10+
blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
11+
reactive-var@1.0.10 # Reactive variable for tracker
12+
jquery@1.11.9 # Helpful client-side library
13+
tracker@1.1.0 # Meteor's client-side reactive programming library
14+
15+
standard-minifier-css@1.1.8 # CSS minifier run for production mode
16+
standard-minifier-js@1.1.8 # JS minifier run for production mode
17+
es5-shim@4.6.13 # ECMAScript 5 compatibility for older browsers.
18+
ecmascript@0.5.7 # Enable ECMAScript2015+ syntax in app code
19+
20+
autopublish@1.0.7 # Publish all data to the clients (for prototyping)
21+
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
22+
react-meteor-data

‎.meteor/platforms

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server
2+
browser

‎.meteor/release

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
METEOR@1.4.0.1

‎.meteor/versions

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
allow-deny@1.0.5
2+
autopublish@1.0.7
3+
autoupdate@1.2.11
4+
babel-compiler@6.9.0
5+
babel-runtime@0.1.10
6+
base64@1.0.9
7+
binary-heap@1.0.9
8+
blaze@2.1.8
9+
blaze-html-templates@1.0.4
10+
blaze-tools@1.0.9
11+
boilerplate-generator@1.0.9
12+
caching-compiler@1.0.6
13+
caching-html-compiler@1.0.6
14+
callback-hook@1.0.9
15+
check@1.2.3
16+
ddp@1.2.5
17+
ddp-client@1.2.9
18+
ddp-common@1.2.6
19+
ddp-server@1.2.10
20+
deps@1.0.12
21+
diff-sequence@1.0.6
22+
ecmascript@0.5.7
23+
ecmascript-runtime@0.3.12
24+
ejson@1.0.12
25+
es5-shim@4.6.13
26+
fastclick@1.0.12
27+
geojson-utils@1.0.9
28+
hot-code-push@1.0.4
29+
html-tools@1.0.10
30+
htmljs@1.0.10
31+
http@1.1.8
32+
id-map@1.0.8
33+
insecure@1.0.7
34+
jquery@1.11.9
35+
launch-screen@1.0.12
36+
livedata@1.0.18
37+
logging@1.1.14
38+
meteor@1.2.16
39+
meteor-base@1.0.4
40+
minifier-css@1.2.13
41+
minifier-js@1.2.13
42+
minimongo@1.0.17
43+
mobile-experience@1.0.4
44+
mobile-status-bar@1.0.12
45+
modules@0.7.5
46+
modules-runtime@0.7.5
47+
mongo@1.1.10
48+
mongo-id@1.0.5
49+
npm-mongo@1.5.45
50+
observe-sequence@1.0.12
51+
ordered-dict@1.0.8
52+
promise@0.8.3
53+
random@1.0.10
54+
react-meteor-data@0.2.9
55+
reactive-var@1.0.10
56+
reload@1.1.10
57+
retry@1.0.8
58+
routepolicy@1.0.11
59+
spacebars@1.0.12
60+
spacebars-compiler@1.0.12
61+
standard-minifier-css@1.1.8
62+
standard-minifier-js@1.1.8
63+
templating@1.1.14
64+
templating-tools@1.0.4
65+
tmeasday:check-npm-versions@0.2.0
66+
tracker@1.1.0
67+
ui@1.0.11
68+
underscore@1.0.9
69+
url@1.0.10
70+
webapp@1.3.10
71+
webapp-hashing@1.0.9

‎client/main.css

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
table.game-board tr td {
2+
border: 1px solid black;
3+
width: 30px;
4+
height: 30px;
5+
text-align: center;
6+
}

‎client/main.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<head>
2+
<title>my-game-site</title>
3+
</head>
4+
<body>
5+
<div id="render-target"></div>
6+
</body>

‎client/main.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import { Meteor } from 'meteor/meteor';
3+
import { render } from 'react-dom';
4+
import App from '../imports/ui/App.jsx';
5+
6+
Meteor.startup(() => {
7+
render(<App />, document.getElementById('render-target'));
8+
});

‎imports/api/collections/games.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Mongo } from 'meteor/mongo';
2+
3+
export default Games = new Mongo.Collection('games');

‎imports/ui/App.jsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { Component } from 'react';
2+
import { createContainer } from 'meteor/react-meteor-data';
3+
import Games from '../api/collections/games.js';
4+
import GameBoard from './GameBoard.jsx';
5+
6+
class App extends Component {
7+
render() {
8+
return (
9+
<div>
10+
{this.props.game?
11+
<GameBoard game={this.props.game}/>
12+
: null}
13+
</div>
14+
)
15+
}
16+
}
17+
18+
export default createContainer(() => {
19+
return {
20+
game: Games.findOne()
21+
};
22+
}, App);

‎imports/ui/GameBoard.jsx

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { Component } from 'react';
2+
3+
export default class GameBoard extends Component {
4+
currentPlayer() {
5+
// determine the current player by counting the filled cells
6+
// if even, then it's first player, otherwise it's second player
7+
let filledCount = 0;
8+
for (let r = 0; r < 3; r++) {
9+
for (let c = 0; c < 3; c++) {
10+
if (this.props.game.board[r][c] !== null) filledCount++;
11+
}
12+
}
13+
return (filledCount % 2 === 0? 0: 1);
14+
}
15+
16+
handleCellClick(row, col) {
17+
let currentPlayer = this.currentPlayer();
18+
let game = this.props.game;
19+
game.board[row][col] = currentPlayer;
20+
Games.update(game._id, {
21+
$set: {board: game.board}
22+
});
23+
}
24+
25+
renderCell(row, col) {
26+
let value = this.props.game.board[row][col];
27+
if (value === 0) return (<td>O</td>);
28+
if (value === 1) return (<td>X</td>);
29+
if (value === null) return (
30+
<td onClick={this.handleCellClick.bind(this, row, col)}></td>
31+
);
32+
}
33+
render() {
34+
return (
35+
<table className="game-board">
36+
<tbody>
37+
<tr>
38+
{this.renderCell(0, 0)}
39+
{this.renderCell(0, 1)}
40+
{this.renderCell(0, 2)}
41+
</tr>
42+
<tr>
43+
{this.renderCell(1, 0)}
44+
{this.renderCell(1, 1)}
45+
{this.renderCell(1, 2)}
46+
</tr>
47+
<tr>
48+
{this.renderCell(2, 0)}
49+
{this.renderCell(2, 1)}
50+
{this.renderCell(2, 2)}
51+
</tr>
52+
</tbody>
53+
</table>
54+
)
55+
}
56+
}

‎package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "my-game-site",
3+
"private": true,
4+
"scripts": {
5+
"start": "meteor run"
6+
},
7+
"dependencies": {
8+
"meteor-node-stubs": "~0.2.0",
9+
"react": "^15.3.0",
10+
"react-addons-pure-render-mixin": "^15.3.0",
11+
"react-dom": "^15.3.0"
12+
}
13+
}

‎server/main.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Meteor } from 'meteor/meteor';
2+
import Games from '../imports/api/collections/games.js'; // import Games collection
3+
4+
Meteor.startup(() => {
5+
// code to run on server at startup
6+
7+
Games.remove({}); // remove all existing game documents
8+
9+
let gameDoc = {
10+
board: [[null, null, null], [null, null, null], [null, null, null]]
11+
};
12+
13+
Games.insert(gameDoc); // insert a new game document into the collection
14+
});

0 commit comments

Comments
 (0)