Skip to content

Commit

Permalink
fix bug in the way the transport notifies client subscribers of conne…
Browse files Browse the repository at this point in the history
…ction changes
  • Loading branch information
nicolodavis committed Oct 25, 2019
1 parent 2f86d92 commit 5a13f00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class _ClientImpl {
subscribe(fn) {
const id = Object.keys(this.subscribers).length;
this.subscribers[id] = fn;
this.transport.subscribe(this.notifySubscribers);
this.transport.subscribe(() => this.notifySubscribers());
this.notifySubscribers();

// Return a handle that allows the caller to unsubscribe.
Expand Down
13 changes: 13 additions & 0 deletions src/client/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,19 @@ describe('subscribe', () => {
);
expect(fn2).not.toBeCalled();
});

test('transport notifies subscribers', () => {
const client = Client({
game: {},
multiplayer: true,
});
const fn = jest.fn();
client.subscribe(fn);
client.start();
fn.mockClear();
client.transport.callback();
expect(fn).toHaveBeenCalled();
});
});

test('override game state', () => {
Expand Down

0 comments on commit 5a13f00

Please sign in to comment.