Skip to content

Commit ed165a8

Browse files
flungloafnicolodavis
authored andcommitted
Add a server sync status field (#307)
* Add a server sync status field * tweak test to verify the public API as opposed to the internal field
1 parent e37e89b commit ed165a8

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/client/client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class _ClientImpl {
9393
this.credentials = credentials;
9494
this.multiplayer = multiplayer;
9595
this.subscribeCallback = () => {};
96+
this.isSynced = false;
9697

9798
this.reducer = CreateGameReducer({
9899
game,
@@ -176,6 +177,7 @@ class _ClientImpl {
176177

177178
case Actions.SYNC: {
178179
this.log = action.log || [];
180+
this.isSynced = true;
179181
break;
180182
}
181183
}
@@ -288,7 +290,7 @@ class _ClientImpl {
288290
const G = this.game.playerView(state.G, state.ctx, this.playerID);
289291

290292
// Combine into return value.
291-
let ret = { ...state, isActive, G, log: this.log };
293+
let ret = { ...state, isActive, isSynced: this.isSynced, G, log: this.log };
292294

293295
const isConnected = this.transport.isConnected;
294296
ret = { ...ret, isConnected };

src/client/client.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ test('isActive', () => {
4949
expect(client.getState().isActive).toBe(false);
5050
});
5151

52+
test('isSynced', () => {
53+
const client = Client({
54+
game: Game({}),
55+
});
56+
57+
expect(client.getState().isSynced).toBe(false);
58+
client.store.dispatch(sync(client.getState(), []));
59+
expect(client.getState().isSynced).toBe(true);
60+
});
61+
5262
describe('step', () => {
5363
const client = Client({
5464
game: Game({

0 commit comments

Comments
 (0)