Skip to content

Commit 5da6cbf

Browse files
committed
Use notifyHost instead of _hostRPC.call
`notifyHost` method has a more strict type (a subset of `Bridge` event that can be passed to the host). By using it everywhere, including in the own class, we prevent possible mistakes (passing incorrect events).
1 parent 7bb7b76 commit 5da6cbf

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/sidebar/services/frame-sync.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class FrameSyncService {
129129
if (frames.length > 0) {
130130
if (frames.every(frame => frame.isAnnotationFetchComplete)) {
131131
if (publicAnns === 0 || publicAnns !== prevPublicAnns) {
132-
this._hostRPC.call(
132+
this.notifyHost(
133133
sidebarToHostEvents.PUBLIC_ANNOTATION_COUNT_CHANGED,
134134
publicAnns
135135
);
@@ -156,7 +156,7 @@ export class FrameSyncService {
156156
// and delete the (unsaved) annotation so it gets un-selected in the
157157
// target document
158158
if (!store.isLoggedIn()) {
159-
this._hostRPC.call(sidebarToHostEvents.OPEN_SIDEBAR);
159+
this.notifyHost(sidebarToHostEvents.OPEN_SIDEBAR);
160160
store.openSidebarPanel('loginPrompt');
161161
this._guestRPC.call(
162162
sidebarToGuestEvents.DELETE_ANNOTATION,
@@ -212,11 +212,11 @@ export class FrameSyncService {
212212
);
213213

214214
this._guestRPC.on(guestToSidebarEvents.OPEN_SIDEBAR, () => {
215-
this._hostRPC.call(sidebarToHostEvents.OPEN_SIDEBAR);
215+
this.notifyHost(sidebarToHostEvents.OPEN_SIDEBAR);
216216
});
217217

218218
this._guestRPC.on(guestToSidebarEvents.CLOSE_SIDEBAR, () => {
219-
this._hostRPC.call(sidebarToHostEvents.CLOSE_SIDEBAR);
219+
this.notifyHost(sidebarToHostEvents.CLOSE_SIDEBAR);
220220
});
221221
};
222222
}

src/sidebar/services/test/frame-sync-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,12 @@ describe('FrameSyncService', () => {
604604
describe('#notifyHost', () => {
605605
it('sends a message to the host frame', () => {
606606
frameSync.connect();
607-
frameSync.notifyHost('openNotebook', 'group-id');
608-
assert.calledWith(hostBridge().call, 'openNotebook', 'group-id');
607+
frameSync.notifyHost(sidebarToHostEvents.OPEN_NOTEBOOK, 'group-id');
608+
assert.calledWith(
609+
hostBridge().call,
610+
sidebarToHostEvents.OPEN_NOTEBOOK,
611+
'group-id'
612+
);
609613
});
610614
});
611615
});

0 commit comments

Comments
 (0)