Skip to content

Commit 957b44f

Browse files
committed
Rename beforeCreateAnnotation to createAnnotation
This is the event that creates the annotation, so it is better to name it in a more obvious way. Context: #3829 (comment)
1 parent 7bb7b76 commit 957b44f

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

src/annotator/annotation-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class AnnotationSync {
7979
return;
8080
}
8181
this.bridge.call(
82-
guestToSidebarEvents.BEFORE_CREATE_ANNOTATION,
82+
guestToSidebarEvents.CREATE_ANNOTATION,
8383
this._format(annotation)
8484
);
8585
});

src/annotator/test/annotation-sync-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('AnnotationSync', () => {
123123
assert.called(fakeBridge.call);
124124
assert.calledWith(
125125
fakeBridge.call,
126-
guestToSidebarEvents.BEFORE_CREATE_ANNOTATION,
126+
guestToSidebarEvents.CREATE_ANNOTATION,
127127
{
128128
msg: ann,
129129
tag: ann.$tag,

src/shared/bridge-events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export const hostToSidebarEvents = {
2929
/**
3030
* Events that the guest sends to the sidebar
3131
*
32-
* @typedef {'beforeCreateAnnotation'|'closeSidebar'|'focusAnnotations'|'openSidebar'|'showAnnotations'|'sync'|'toggleAnnotationSelection'} GuestToSidebarEvent
33-
* @type {Record<'BEFORE_CREATE_ANNOTATION'|'CLOSE_SIDEBAR'|'FOCUS_ANNOTATIONS'|'OPEN_SIDEBAR'|'SHOW_ANNOTATIONS'|'SYNC'|'TOGGLE_ANNOTATION_SELECTION', GuestToSidebarEvent>}
32+
* @typedef {'createAnnotation'|'closeSidebar'|'focusAnnotations'|'openSidebar'|'showAnnotations'|'sync'|'toggleAnnotationSelection'} GuestToSidebarEvent
33+
* @type {Record<'CREATE_ANNOTATION'|'CLOSE_SIDEBAR'|'FOCUS_ANNOTATIONS'|'OPEN_SIDEBAR'|'SHOW_ANNOTATIONS'|'SYNC'|'TOGGLE_ANNOTATION_SELECTION', GuestToSidebarEvent>}
3434
*/
3535
export const guestToSidebarEvents = {
3636
/**
3737
* The guest is asking the sidebar to create an annotation.
3838
*/
39-
BEFORE_CREATE_ANNOTATION: 'beforeCreateAnnotation',
39+
CREATE_ANNOTATION: 'createAnnotation',
4040

4141
/**
4242
* The guest is asking the sidebar to relay the message to open the sidebar.

src/sidebar/services/frame-sync.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,26 @@ export class FrameSyncService {
147147
*/
148148
this._setupSyncFromGuests = () => {
149149
// A new annotation, note or highlight was created in the frame
150-
this._guestRPC.on(
151-
guestToSidebarEvents.BEFORE_CREATE_ANNOTATION,
152-
event => {
153-
const annot = Object.assign({}, event.msg, { $tag: event.tag });
154-
// If user is not logged in, we can't really create a meaningful highlight
155-
// or annotation. Instead, we need to open the sidebar, show an error,
156-
// and delete the (unsaved) annotation so it gets un-selected in the
157-
// target document
158-
if (!store.isLoggedIn()) {
159-
this._hostRPC.call(sidebarToHostEvents.OPEN_SIDEBAR);
160-
store.openSidebarPanel('loginPrompt');
161-
this._guestRPC.call(
162-
sidebarToGuestEvents.DELETE_ANNOTATION,
163-
formatAnnot(annot)
164-
);
165-
return;
166-
}
167-
inFrame.add(event.tag);
168-
169-
// Create the new annotation in the sidebar.
170-
annotationsService.create(annot);
150+
this._guestRPC.on(guestToSidebarEvents.CREATE_ANNOTATION, event => {
151+
const annot = Object.assign({}, event.msg, { $tag: event.tag });
152+
// If user is not logged in, we can't really create a meaningful highlight
153+
// or annotation. Instead, we need to open the sidebar, show an error,
154+
// and delete the (unsaved) annotation so it gets un-selected in the
155+
// target document
156+
if (!store.isLoggedIn()) {
157+
this._hostRPC.call(sidebarToHostEvents.OPEN_SIDEBAR);
158+
store.openSidebarPanel('loginPrompt');
159+
this._guestRPC.call(
160+
sidebarToGuestEvents.DELETE_ANNOTATION,
161+
formatAnnot(annot)
162+
);
163+
return;
171164
}
172-
);
165+
inFrame.add(event.tag);
166+
167+
// Create the new annotation in the sidebar.
168+
annotationsService.create(annot);
169+
});
173170

174171
// Map of annotation tag to anchoring status
175172
// ('anchored'|'orphan'|'timeout').

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ describe('FrameSyncService', () => {
328328
fakeStore.isLoggedIn.returns(true);
329329
const ann = { target: [] };
330330

331-
guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, {
331+
guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, {
332332
tag: 't1',
333333
msg: ann,
334334
});
@@ -352,7 +352,7 @@ describe('FrameSyncService', () => {
352352
it('should not create an annotation in the sidebar', () => {
353353
const ann = { target: [] };
354354

355-
guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, {
355+
guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, {
356356
tag: 't1',
357357
msg: ann,
358358
});
@@ -362,7 +362,7 @@ describe('FrameSyncService', () => {
362362

363363
it('should open the sidebar', () => {
364364
const ann = { target: [] };
365-
guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, {
365+
guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, {
366366
tag: 't1',
367367
msg: ann,
368368
});
@@ -372,7 +372,7 @@ describe('FrameSyncService', () => {
372372

373373
it('should open the login prompt panel', () => {
374374
const ann = { target: [] };
375-
guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, {
375+
guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, {
376376
tag: 't1',
377377
msg: ann,
378378
});
@@ -382,7 +382,7 @@ describe('FrameSyncService', () => {
382382

383383
it('should send a "deleteAnnotation" message to the frame', () => {
384384
const ann = { target: [] };
385-
guestBridge().emit(guestToSidebarEvents.BEFORE_CREATE_ANNOTATION, {
385+
guestBridge().emit(guestToSidebarEvents.CREATE_ANNOTATION, {
386386
tag: 't1',
387387
msg: ann,
388388
});

0 commit comments

Comments
 (0)