Skip to content

Commit

Permalink
Remove unused Window argument to onConnect callback
Browse files Browse the repository at this point in the history
This argument was not used by any callers of `Bridge#onConnect` and
removing it eliminates a difference between creating a channel that uses
`Window.postMessage` vs one that uses `MessagePort`.
  • Loading branch information
robertknight committed Jul 21, 2021
1 parent 95aea61 commit 42369e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/shared/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Bridge {
this.links = [];
/** @type {Record<string, (...args: any[]) => void>} */
this.channelListeners = {};
/** @type {Array<(channel: RPC, window?: Window) => void>} */
/** @type {Array<(channel: RPC) => void>} */
this.onConnectListeners = [];
}

Expand Down Expand Up @@ -113,7 +113,7 @@ export default class Bridge {
return;
}
connected = true;
this.onConnectListeners.forEach(cb => cb(channel, source));
this.onConnectListeners.forEach(cb => cb(channel));
};

const connect = (_token, cb) => {
Expand Down Expand Up @@ -227,7 +227,7 @@ export default class Bridge {
/**
* Add a listener to be called upon a new connection.
*
* @param {(channel: RPC, window?: Window) => void} listener
* @param {(channel: RPC) => void} listener
*/
onConnect(listener) {
this.onConnectListeners.push(listener);
Expand Down
6 changes: 3 additions & 3 deletions src/shared/test/bridge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('shared/bridge', () => {

runConnectHandler(channel);

assert.calledWith(onConnectCallback, channel, fakeWindow);
assert.calledWith(onConnectCallback, channel);
});

it('does not run callback if a Window channel connects with wrong token', () => {
Expand Down Expand Up @@ -298,8 +298,8 @@ describe('shared/bridge', () => {

runConnectHandler(channel);

assert.calledWith(onConnectCallback1, channel, fakeWindow);
assert.calledWith(onConnectCallback2, channel, fakeWindow);
assert.calledWith(onConnectCallback1, channel);
assert.calledWith(onConnectCallback2, channel);
});

it('only invokes `onConnect` callback once', () => {
Expand Down

0 comments on commit 42369e6

Please sign in to comment.