Skip to content

Commit 0327737

Browse files
Apply suggestions from code review
Co-authored-by: Robert Knight <[email protected]>
1 parent 1748ca4 commit 0327737

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

src/annotator/annotation-sync.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
2+
* @typedef {import('../shared/bridge').Bridge<GuestToSidebarEvent,SidebarToGuestEvent>} SidebarBridge
23
* @typedef {import('../types/annotator').AnnotationData} AnnotationData
34
* @typedef {import('../types/annotator').Destroyable} Destroyable
45
* @typedef {import('../types/bridge-events').GuestToSidebarEvent} GuestToSidebarEvent
56
* @typedef {import('../types/bridge-events').SidebarToGuestEvent} SidebarToGuestEvent
67
* @typedef {import('./util/emitter').EventBus} EventBus
78
*/
89

9-
/**
10-
* @template {GuestToSidebarEvent} T
11-
* @template {SidebarToGuestEvent} U
12-
* @typedef {import('../shared/bridge').Bridge<T,U>} Bridge
13-
*/
14-
1510
/**
1611
* Message sent between the sidebar and annotator about an annotation that has
1712
* changed.
@@ -33,7 +28,7 @@
3328
export class AnnotationSync {
3429
/**
3530
* @param {EventBus} eventBus - Event bus for communicating with the annotator code (eg. the Guest)
36-
* @param {Bridge<GuestToSidebarEvent,SidebarToGuestEvent>} bridge - Channel for communicating with the sidebar
31+
* @param {SidebarBridge} bridge - Channel for communicating with the sidebar
3732
*/
3833
constructor(eventBus, bridge) {
3934
this._emitter = eventBus.createEmitter();

src/annotator/test/sidebar-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ describe('Sidebar', () => {
358358
});
359359
});
360360

361-
describe('on "loginRequest" event', () => {
361+
describe('on "loginRequested" event', () => {
362362
it('calls the onLoginRequest callback function if one was provided', () => {
363363
const onLoginRequest = sandbox.stub();
364364
createSidebar({ services: [{ onLoginRequest }] });
@@ -425,7 +425,7 @@ describe('Sidebar', () => {
425425
});
426426
});
427427

428-
describe('on LOGOUT_REQUESTED event', () =>
428+
describe('on "logoutRequested" event', () =>
429429
it('calls the onLogoutRequest callback function', () => {
430430
const onLogoutRequest = sandbox.stub();
431431
createSidebar({ services: [{ onLogoutRequest }] });
@@ -435,7 +435,7 @@ describe('Sidebar', () => {
435435
assert.called(onLogoutRequest);
436436
}));
437437

438-
describe('on "signupRequest" event', () =>
438+
describe('on "signupRequested" event', () =>
439439
it('calls the onSignupRequest callback function', () => {
440440
const onSignupRequest = sandbox.stub();
441441
createSidebar({ services: [{ onSignupRequest }] });
@@ -445,7 +445,7 @@ describe('Sidebar', () => {
445445
assert.called(onSignupRequest);
446446
}));
447447

448-
describe('on "profileRequest" event', () =>
448+
describe('on "profileRequested" event', () =>
449449
it('calls the onProfileRequest callback function', () => {
450450
const onProfileRequest = sandbox.stub();
451451
createSidebar({ services: [{ onProfileRequest }] });

src/sidebar/components/test/HypothesisApp-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ describe('HypothesisApp', () => {
223223
fakeServiceConfig.returns({});
224224
});
225225

226-
it('sends "signupRequest" event', () => {
226+
it('sends "signupRequested" event', () => {
227227
const wrapper = createComponent();
228228
clickSignUp(wrapper);
229229
assert.calledWith(fakeFrameSync.notifyHost, 'signupRequested');
@@ -287,9 +287,9 @@ describe('HypothesisApp', () => {
287287
assert.called(fakeToastMessenger.error);
288288
});
289289

290-
it('sends LOGIN_REQUESTED event to host page if using a third-party service', async () => {
290+
it('sends "loginRequested" event to host page if using a third-party service', async () => {
291291
// If the client is using a third-party annotation service then clicking
292-
// on a login button should send the LOGIN_REQUESTED event over the bridge
292+
// on a login button should send the "loginRequested" event over the bridge
293293
// (so that the partner site we're embedded in can do its own login
294294
// thing).
295295
fakeServiceConfig.returns({});
@@ -402,15 +402,15 @@ describe('HypothesisApp', () => {
402402

403403
addCommonLogoutTests();
404404

405-
it('sends LOGOUT_REQUESTED', async () => {
405+
it('sends "logoutRequested"', async () => {
406406
const wrapper = createComponent();
407407
await clickLogOut(wrapper);
408408

409409
assert.calledOnce(fakeFrameSync.notifyHost);
410410
assert.calledWithExactly(fakeFrameSync.notifyHost, 'logoutRequested');
411411
});
412412

413-
it('does not send LOGOUT_REQUESTED if the user cancels the prompt', async () => {
413+
it('does not send "logoutRequested" if the user cancels the prompt', async () => {
414414
fakeStore.countDrafts.returns(1);
415415
fakeConfirm.returns(false);
416416

src/types/bridge-events.d.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
2-
* This module defines the set of global events that are dispatched across the
3-
* the bridge(s) between the sidebar-host and sidebar-guest(s).
2+
* This module defines the events that are sent between frames with different
3+
* roles in the client (guest, host, sidebar).
44
*/
55

66
/**
77
* Events that the host sends to the sidebar
88
*/
99
export type HostToSidebarEvent =
1010
/**
11-
* The host is asking the sidebar to delete a frame.
11+
* The host informs the sidebar that a guest frame has been destroyed
1212
*/
1313
| 'destroyFrame'
1414

1515
/**
16-
* The host is asking the sidebar to set the annotation highlights on/off.
16+
* Highlights have been toggled on/off.
1717
*/
1818
| 'setVisibleHighlights'
1919

@@ -32,7 +32,7 @@ export type GuestToSidebarEvent =
3232
| 'beforeCreateAnnotation'
3333

3434
/**
35-
* The guest is asking the sidebar to relay the message to open the sidebar.
35+
* The guest is asking the sidebar to relay the message to the host to close the sidebar.
3636
*/
3737
| 'closeSidebar'
3838

@@ -42,7 +42,7 @@ export type GuestToSidebarEvent =
4242
| 'focusAnnotations'
4343

4444
/**
45-
* The guest is asking the sidebar to relay the message to open the sidebar.
45+
* The guest is asking the sidebar to relay the message to the host to open the sidebar.
4646
*/
4747
| 'openSidebar'
4848

@@ -52,7 +52,7 @@ export type GuestToSidebarEvent =
5252
| 'showAnnotations'
5353

5454
/**
55-
* The guest notifies the sidebar to synchronize about the anchoring status of annotations.
55+
* The guest informs the sidebar whether annotations were successfully anchored
5656
*/
5757
| 'sync'
5858

@@ -76,7 +76,7 @@ export type SidebarToGuestEvent =
7676
| 'focusAnnotations'
7777

7878
/**
79-
* The sidebar is asking the guest(s) to get the document metadata.
79+
* The sidebar is asking the guest(s) the URL and other metadata about the document.
8080
*/
8181
| 'getDocumentInfo'
8282

@@ -100,31 +100,34 @@ export type SidebarToGuestEvent =
100100
*/
101101
export type SidebarToHostEvent =
102102
/**
103-
* The sidebar relays to the host to open the sidebar.
103+
* The sidebar relays to the host to close the sidebar.
104104
*/
105105
| 'closeSidebar'
106106

107107
/**
108-
* The updated feature flags for the user
108+
* The sidebar informs the host to update the Hypothesis configuration to enable/disable additional features
109109
*/
110110
| 'featureFlagsUpdated'
111111

112112
/**
113113
* The sidebar is asking the host to open the partner site help page.
114+
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onhelprequest
114115
*/
115116
| 'helpRequested'
116117

117118
/**
118119
* The sidebar is asking the host to do a partner site log in
119120
* (for example pop up a log in window). This is used when the client is
120121
* embedded in a partner site and a log in button in the client is clicked.
122+
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onloginrequest
121123
*/
122124
| 'loginRequested'
123125

124126
/**
125127
* The sidebar is asking the host to do a partner site log out.
126128
* This is used when the client is embedded in a partner site and a log out
127129
* button in the client is clicked.
130+
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onlogoutrequest
128131
*/
129132
| 'logoutRequested'
130133

@@ -134,23 +137,26 @@ export type SidebarToHostEvent =
134137
| 'openNotebook'
135138

136139
/**
137-
* The sidebar is asking the host to open the sidebar (side-effect of
138-
* creating an annotation).
140+
* The sidebar is asking the host to open the sidebar (side-effect of creating
141+
* an annotation).
139142
*/
140143
| 'openSidebar'
141144

142145
/**
143146
* The sidebar is asking the host to open the partner site profile page.
147+
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onprofilerequest
144148
*/
145149
| 'profileRequested'
146150

147151
/**
148-
* The sidebar inform the host to update the number of annotations in the partner site.
152+
* The sidebar informs the host to update the annotation counter in the partner site.
153+
* https://h.readthedocs.io/projects/client/en/latest/publishers/host-page-integration/#cmdoption-arg-data-hypothesis-annotation-count
149154
*/
150155
| 'publicAnnotationCountChanged'
151156

152157
/**
153158
* The sidebar is asking the host to do a partner site sign-up.
159+
* https://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-onsignuprequest
154160
*/
155161
| 'signupRequested';
156162

0 commit comments

Comments
 (0)