Skip to content

Commit a32b7a8

Browse files
committed
Try to revert for testing
1 parent 7325ad0 commit a32b7a8

File tree

2 files changed

+7
-38
lines changed

2 files changed

+7
-38
lines changed

src/game.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function processEvent(internalGameState, event) {
401401
updateBoard(internalGameState, event, cards);
402402
}
403403

404-
export function computeState(gameData, gameMode, newEvents = null) {
404+
export function computeState(gameData, gameMode) {
405405
if (!modes.hasOwnProperty(gameMode)) {
406406
throw new Error(`invalid gameMode: ${gameMode}`);
407407
}
@@ -440,21 +440,10 @@ export function computeState(gameData, gameMode, newEvents = null) {
440440
};
441441

442442
if (gameData.events) {
443-
let events;
444-
// Array.sort() is guaranteed to be stable in since around 2018.
445-
if (newEvents?.size) {
446-
// Always sort new events (with approximate times) after old events.
447-
events = Object.entries(gameData.events)
448-
.sort(
449-
([k1, e1], [k2, e2]) =>
450-
newEvents.has(k1) - newEvents.has(k2) || e1.time - e2.time
451-
)
452-
.map(([k, e]) => e);
453-
} else {
454-
events = Object.values(gameData.events).sort(
455-
(e1, e2) => e1.time - e2.time
456-
);
457-
}
443+
// Array.sort() is guaranteed to be stable in since around 2018
444+
const events = Object.values(gameData.events).sort(
445+
(e1, e2) => e1.time - e2.time
446+
);
458447
for (const event of events) {
459448
processEvent(internalGameState, event);
460449
}

src/pages/GamePage.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ function GamePage({ match }) {
124124

125125
const [game, loadingGame] = useFirebaseRef(`games/${gameId}`);
126126
const [gameData, loadingGameData] = useFirebaseRef(`gameData/${gameId}`);
127-
const newEvents = useRef(new Set());
128127
const [hasNextGame] = useFirebaseRef(
129128
game?.status === "done" && (!game.users || !(user.id in game.users))
130129
? `games/${nextGameId}/status`
@@ -202,11 +201,7 @@ function GamePage({ match }) {
202201
lastKeptSet,
203202
} = useMemo(() => {
204203
if (!gameData) return {};
205-
const state = computeState(
206-
{ ...gameData, random, deck },
207-
gameMode,
208-
newEvents.current
209-
);
204+
const state = computeState({ ...gameData, random, deck }, gameMode);
210205
const { current, boardSize, findState, history } = state;
211206
const board = current.slice(0, boardSize);
212207
const answer = findSet(board, gameMode, findState);
@@ -256,29 +251,14 @@ function GamePage({ match }) {
256251
if (numHints) {
257252
firebase.database().ref(`gameData/${gameId}/hints`).remove();
258253
}
259-
const eventRef = firebase
254+
firebase
260255
.database()
261256
.ref(`gameData/${gameId}/events`)
262257
.push({
263258
...event,
264259
user: user.id,
265260
time: firebase.database.ServerValue.TIMESTAMP,
266261
});
267-
// Track "new" events that have approximate times. An event is new since
268-
// the time it was created until its time is updated from the server.
269-
// This happens when our callback is called the second time (the first
270-
// time it is called with the approximate time).
271-
const eventKey = eventRef.key;
272-
const timeRef = eventRef.child("time");
273-
newEvents.current.add(eventKey);
274-
let updateCount = 0;
275-
const timeUpdated = () => {
276-
if (++updateCount === 2) {
277-
newEvents.current.delete(eventKey);
278-
timeRef.off("value", timeUpdated);
279-
}
280-
};
281-
timeRef.on("value", timeUpdated);
282262
}
283263

284264
const hint = game.enableHint && answer ? answer.slice(0, numHints) : null;

0 commit comments

Comments
 (0)