Skip to content

Commit ed51fac

Browse files
committed
Updating to 3.0
1 parent 29af958 commit ed51fac

7 files changed

Lines changed: 138 additions & 130 deletions

File tree

tic-tac-toe/.meteor/packages

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
# 'meteor add' and 'meteor remove' will edit this file for you,
55
# but you can also edit it by hand.
66

7-
meteor-base@1.5.1 # Packages every Meteor app needs to have
8-
mobile-experience@1.1.0 # Packages for a great mobile UX
9-
mongo@1.15.0 # The database Meteor supports right now
10-
reactive-var@1.0.11 # Reactive variable for tracker
7+
meteor-base@1.5.2-beta300.6 # Packages every Meteor app needs to have
8+
mobile-experience@1.1.1-beta300.6 # Packages for a great mobile UX
9+
mongo@2.0.0-beta300.6 # The database Meteor supports right now
10+
reactive-var@1.0.13-beta300.6 # Reactive variable for tracker
1111

12-
standard-minifier-css@1.8.1 # CSS minifier run for production mode
13-
standard-minifier-js@2.8.0 # JS minifier run for production mode
14-
es5-shim@4.8.0 # ECMAScript 5 compatibility for older browsers
15-
ecmascript@0.16.2 # Enable ECMAScript2015+ syntax in app code
16-
typescript@4.5.4 # Enable TypeScript syntax in .ts and .tsx modules
17-
shell-server@0.5.0 # Server-side component of the `meteor shell` command
18-
hot-module-replacement@0.5.1 # Update client in development without reloading the page
12+
standard-minifier-css@1.9.3-beta300.6 # CSS minifier run for production mode
13+
standard-minifier-js@3.0.0-beta300.6 # JS minifier run for production mode
14+
es5-shim@4.8.1-beta300.6 # ECMAScript 5 compatibility for older browsers
15+
ecmascript@0.16.8-beta300.6 # Enable ECMAScript2015+ syntax in app code
16+
typescript@5.3.3-beta300.6 # Enable TypeScript syntax in .ts and .tsx modules
17+
shell-server@0.6.0-beta300.6 # Server-side component of the `meteor shell` command
18+
hot-module-replacement@0.5.4-beta300.6 # Update client in development without reloading the page
1919

20-
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
21-
static-html@1.3.2 # Define static page content in .html files
22-
react-meteor-data # React higher-order component for reactively tracking Meteor data
20+
insecure@1.0.8-beta300.6 # Allow all DB writes from clients (for prototyping)
21+
static-html@1.3.3-beta300.6 # Define static page content in .html files
22+
react-meteor-data@3.0.0-beta300.1

tic-tac-toe/.meteor/release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
METEOR@2.7.3
1+
METEOR@3.0-beta.6

tic-tac-toe/.meteor/versions

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,74 @@
1-
allow-deny@1.1.1
2-
autoupdate@1.8.0
3-
babel-compiler@7.9.2
4-
babel-runtime@1.5.1
5-
base64@1.0.12
6-
binary-heap@1.0.11
7-
blaze-tools@1.1.3
8-
boilerplate-generator@1.7.1
9-
caching-compiler@1.2.2
10-
caching-html-compiler@1.2.1
11-
callback-hook@1.4.0
12-
check@1.3.1
13-
ddp@1.4.0
14-
ddp-client@2.5.0
15-
ddp-common@1.4.0
16-
ddp-server@2.5.0
17-
diff-sequence@1.1.1
18-
dynamic-import@0.7.2
19-
ecmascript@0.16.2
20-
ecmascript-runtime@0.8.0
21-
ecmascript-runtime-client@0.12.1
22-
ecmascript-runtime-server@0.11.0
23-
ejson@1.1.2
24-
es5-shim@4.8.0
25-
fetch@0.1.1
26-
geojson-utils@1.0.10
27-
hot-code-push@1.0.4
28-
hot-module-replacement@0.5.1
29-
html-tools@1.1.3
30-
htmljs@1.1.1
31-
id-map@1.1.1
32-
insecure@1.0.7
33-
inter-process-messaging@0.1.1
34-
launch-screen@1.3.0
35-
logging@1.3.1
36-
meteor@1.10.0
37-
meteor-base@1.5.1
38-
minifier-css@1.6.1
39-
minifier-js@2.7.5
40-
minimongo@1.8.0
41-
mobile-experience@1.1.0
42-
mobile-status-bar@1.1.0
43-
modern-browsers@0.1.8
44-
modules@0.18.0
45-
modules-runtime@0.13.0
46-
modules-runtime-hot@0.14.0
47-
mongo@1.15.0
48-
mongo-decimal@0.1.3
49-
mongo-dev-server@1.1.0
50-
mongo-id@1.0.8
51-
npm-mongo@4.3.1
52-
ordered-dict@1.1.0
53-
promise@0.12.0
54-
random@1.2.0
55-
react-fast-refresh@0.2.3
56-
react-meteor-data@2.5.1
57-
reactive-var@1.0.11
58-
reload@1.3.1
59-
retry@1.1.0
60-
routepolicy@1.1.1
61-
shell-server@0.5.0
62-
socket-stream-client@0.5.0
63-
spacebars-compiler@1.3.1
64-
standard-minifier-css@1.8.2
65-
standard-minifier-js@2.8.1
66-
static-html@1.3.2
67-
templating-tools@1.2.2
68-
tracker@1.2.0
69-
typescript@4.5.4
70-
underscore@1.0.10
71-
webapp@1.13.1
72-
webapp-hashing@1.1.0
1+
allow-deny@2.0.0-beta300.6
2+
autoupdate@2.0.0-beta300.6
3+
babel-compiler@7.11.0-beta300.6
4+
babel-runtime@1.5.2-beta300.6
5+
base64@1.0.13-beta300.6
6+
binary-heap@1.0.12-beta300.6
7+
blaze-tools@2.0.0-alpha300.17
8+
boilerplate-generator@2.0.0-beta300.6
9+
caching-compiler@2.0.0-beta300.6
10+
caching-html-compiler@2.0.0-alpha300.17
11+
callback-hook@1.6.0-beta300.6
12+
check@1.3.3-beta300.6
13+
core-runtime@1.0.0-beta300.6
14+
ddp@1.4.2-beta300.6
15+
ddp-client@3.0.0-beta300.6
16+
ddp-common@1.4.1-beta300.6
17+
ddp-server@3.0.0-beta300.6
18+
diff-sequence@1.1.3-beta300.6
19+
dynamic-import@0.7.4-beta300.6
20+
ecmascript@0.16.8-beta300.6
21+
ecmascript-runtime@0.8.2-beta300.6
22+
ecmascript-runtime-client@0.12.2-beta300.6
23+
ecmascript-runtime-server@0.11.1-beta300.6
24+
ejson@1.1.4-beta300.6
25+
es5-shim@4.8.1-beta300.6
26+
facts-base@1.0.2-beta300.6
27+
fetch@0.1.4-beta300.6
28+
geojson-utils@1.0.12-beta300.6
29+
hot-code-push@1.0.5-beta300.6
30+
hot-module-replacement@0.5.4-beta300.6
31+
html-tools@2.0.0-alpha300.17
32+
htmljs@2.0.0-alpha300.17
33+
id-map@1.2.0-beta300.6
34+
insecure@1.0.8-beta300.6
35+
inter-process-messaging@0.1.2-beta300.6
36+
launch-screen@1.3.1-beta300.6
37+
logging@1.3.3-beta300.6
38+
meteor@2.0.0-beta300.6
39+
meteor-base@1.5.2-beta300.6
40+
minifier-css@2.0.0-beta300.6
41+
minifier-js@3.0.0-beta300.6
42+
minimongo@2.0.0-beta300.6
43+
mobile-experience@1.1.1-beta300.6
44+
mobile-status-bar@1.1.1-beta300.6
45+
modern-browsers@0.1.10-beta300.6
46+
modules@0.19.1-beta300.6
47+
modules-runtime@0.13.2-beta300.6
48+
modules-runtime-hot@0.14.3-beta300.6
49+
mongo@2.0.0-beta300.6
50+
mongo-decimal@0.1.4-beta300.6
51+
mongo-dev-server@1.1.1-beta300.6
52+
mongo-id@1.0.9-beta300.6
53+
npm-mongo@4.16.1-beta300.6
54+
ordered-dict@1.2.0-beta300.6
55+
promise@1.0.0-beta300.6
56+
random@1.2.2-beta300.6
57+
react-fast-refresh@0.2.8-beta300.6
58+
react-meteor-data@3.0.0-beta300.1
59+
reactive-var@1.0.13-beta300.6
60+
reload@1.3.2-beta300.6
61+
retry@1.1.1-beta300.6
62+
routepolicy@1.1.2-beta300.6
63+
shell-server@0.6.0-beta300.6
64+
socket-stream-client@0.5.2-beta300.6
65+
spacebars-compiler@2.0.0-alpha300.17
66+
standard-minifier-css@1.9.3-beta300.6
67+
standard-minifier-js@3.0.0-beta300.6
68+
static-html@1.3.3-beta300.6
69+
templating-tools@2.0.0-alpha300.17
70+
tracker@1.3.3-beta300.6
71+
typescript@5.3.3-beta300.6
72+
underscore@1.0.14-beta300.6
73+
webapp@2.0.0-beta300.6
74+
webapp-hashing@1.1.2-beta300.6

tic-tac-toe/imports/api/rooms.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Mongo } from "meteor/mongo";
2+
import { Meteor } from "meteor/meteor";
23

34
export const RoomCollection = new Mongo.Collection("rooms");
45

@@ -21,47 +22,52 @@ function checkEndGame(gameState) {
2122
}
2223

2324
Meteor.methods({
24-
createRoom() {
25-
const roomId = RoomCollection.insert({
25+
async createRoom() {
26+
const roomId = await RoomCollection.insertAsync({
2627
createdAt: new Date(),
2728
capacity: 2,
2829
gameState: new Array(9).fill("empty"),
2930
colorTurn: "cross",
30-
winner: null
31+
winner: null,
3132
});
32-
return RoomCollection.findOne(roomId);
33+
return RoomCollection.findOneAsync(roomId);
3334
},
34-
joinRoom({ roomId }) {
35-
RoomCollection.update({ _id: roomId, capacity: { $gte: 1 } }, { $inc: { capacity: -1 } })
36-
const room = RoomCollection.findOne(roomId)
35+
async joinRoom({ roomId }) {
36+
await RoomCollection.updateAsync(
37+
{ _id: roomId, capacity: { $gte: 1 } },
38+
{ $inc: { capacity: -1 } }
39+
);
40+
const room = await RoomCollection.findOneAsync(roomId);
3741
if (!room) {
38-
throw new Error("Room not found, or full!");
42+
throw new Meteor.Error("Room not found, or full!");
3943
}
4044
return {
4145
room,
42-
color: room.capacity === 1 ? "cross" : "circle"
46+
color: room.capacity === 1 ? "cross" : "circle",
4347
};
4448
},
45-
makePlay({ roomId, playState: { color, play } }) {
49+
async makePlay({ roomId, playState: { color, play } }) {
4650
const otherColor = color === "cross" ? "circle" : "cross";
4751
const query = {
4852
_id: roomId,
4953
colorTurn: color,
5054
winner: null,
51-
[`gameState.${play}`]: "empty"
55+
[`gameState.${play}`]: "empty",
5256
};
53-
RoomCollection.update(query, { $set: { colorTurn: otherColor, [`gameState.${play}`]: color } })
54-
const room = RoomCollection.findOne(roomId)
57+
await RoomCollection.updateAsync(query, {
58+
$set: { colorTurn: otherColor, [`gameState.${play}`]: color },
59+
});
60+
const room = await RoomCollection.findOneAsync(roomId);
5561

5662
if (!room) {
5763
throw new Meteor.Error("invalid-play");
5864
}
5965
const winner = checkEndGame(room.gameState);
6066
if (winner && winner !== "empty") {
61-
RoomCollection.update(roomId, { $set: { winner } })
62-
return RoomCollection.findOne(roomId)
67+
await RoomCollection.updateAsync(roomId, { $set: { winner } });
68+
return await RoomCollection.findOneAsync(roomId);
6369
}
6470

6571
return room;
66-
}
72+
},
6773
});

tic-tac-toe/imports/ui/GameScreen.jsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./game.css";
22
import React, { useEffect } from "react";
33
import { useHistory, useLocation, useParams } from "react-router";
4-
import { useTracker } from "meteor/react-meteor-data";
4+
import { useTracker, useFind } from "meteor/react-meteor-data";
55
import { RoomCollection } from "../api/rooms";
66

77
const Slot = ({ id, room: { gameState, _id } }) => {
@@ -10,18 +10,21 @@ const Slot = ({ id, room: { gameState, _id } }) => {
1010
return (
1111
<div
1212
className="slot"
13-
onClick={() => {
14-
Meteor.call(
15-
"makePlay",
16-
{ roomId: _id, playState: { play: id - 1, color } },
17-
err => {
18-
if (err && err.error === "invalid-play") {
19-
alert("This move is invalid. You might need to wait for your turn!")
20-
} else if(err) {
21-
alert(err.message);
22-
}
13+
onClick={async () => {
14+
try {
15+
await Meteor.callAsync("makePlay", {
16+
roomId: _id,
17+
playState: { play: id - 1, color },
18+
});
19+
} catch (e) {
20+
if (e.error === "invalid-play") {
21+
alert(
22+
"This move is invalid. You might need to wait for your turn!"
23+
);
24+
} else {
25+
alert(e.message);
2326
}
24-
);
27+
}
2528
}}
2629
>
2730
{gameState[id - 1] === "cross" ? <img src={"/cross.png"} /> : ""}
@@ -34,15 +37,14 @@ export const GameScreen = () => {
3437
const { id } = useParams();
3538
const location = useLocation();
3639
const history = useHistory();
37-
3840
const { color } = location.state;
3941
const roomLoading = useTracker(() => {
4042
// Note that this subscription will get cleaned up
4143
// when your component is unmounted or deps change.
4244
const handle = Meteor.subscribe("room", { _id: id });
4345
return !handle.ready();
4446
}, [id]);
45-
const room = useTracker(() => RoomCollection.findOne({ _id: id }), [id]);
47+
const [room] = useFind(() => RoomCollection.find({ _id: id }), [id]);
4648

4749
useEffect(() => {
4850
if (room && room.winner) {

tic-tac-toe/imports/ui/RoomList.jsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { useHistory } from "react-router";
55

66
export const RoomList = () => {
77
const history = useHistory();
8-
const listLoading = useSubscribe('rooms')
8+
const listLoading = useSubscribe("rooms");
99
const rooms = useFind(() => RoomCollection.find({}), []);
1010

1111
if (listLoading()) return "Loading...";
1212
return (
1313
<div>
1414
<button
15-
onClick={() => {
16-
Meteor.call("createRoom");
15+
onClick={async () => {
16+
await Meteor.callAsync("createRoom");
1717
}}
1818
>
1919
{" "}
@@ -28,10 +28,8 @@ export const RoomList = () => {
2828
<button
2929
disabled={capacity <= 0}
3030
onClick={() => {
31-
Meteor.call(
32-
"joinRoom",
33-
{ roomId: _id },
34-
(err, { room, color }) => {
31+
Meteor.callAsync("joinRoom", { roomId: _id }).then(
32+
({ room, color }) => {
3533
history.push(`/game/${room._id}`, { color });
3634
}
3735
);

tic-tac-toe/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)