From 750b30fee1d73bde7a7e7804e1eac72c8008a6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Sanz=20Garc=C3=ADa?= Date: Thu, 14 Oct 2021 14:44:56 +0200 Subject: [PATCH] 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: https://github.com/hypothesis/client/pull/3829#discussion_r726880585 --- src/annotator/annotation-sync.js | 2 +- src/annotator/test/annotation-sync-test.js | 4 ++-- src/sidebar/services/frame-sync.js | 2 +- src/sidebar/services/test/frame-sync-test.js | 10 +++++----- src/types/bridge-events.d.ts | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/annotator/annotation-sync.js b/src/annotator/annotation-sync.js index 95352188dee..cd10a814b00 100644 --- a/src/annotator/annotation-sync.js +++ b/src/annotator/annotation-sync.js @@ -77,7 +77,7 @@ export class AnnotationSync { if (annotation.$tag) { return; } - this._sidebar.call('beforeCreateAnnotation', this._format(annotation)); + this._sidebar.call('createAnnotation', this._format(annotation)); }); } diff --git a/src/annotator/test/annotation-sync-test.js b/src/annotator/test/annotation-sync-test.js index 6f56de6d457..b5f6c2d8f65 100644 --- a/src/annotator/test/annotation-sync-test.js +++ b/src/annotator/test/annotation-sync-test.js @@ -108,7 +108,7 @@ describe('AnnotationSync', () => { describe('handling events from the annotator', () => { describe('on "beforeAnnotationCreated" event', () => { - it('calls "beforeCreateAnnotation" RPC method in the sidebar', () => { + it('calls "createAnnotation" RPC method in the sidebar', () => { // nb. Setting an empty `$tag` here matches what `Guest#createAnnotation` // does. const ann = { id: 1, $tag: '' }; @@ -117,7 +117,7 @@ describe('AnnotationSync', () => { emitter.publish('beforeAnnotationCreated', ann); assert.called(fakeBridge.call); - assert.calledWith(fakeBridge.call, 'beforeCreateAnnotation', { + assert.calledWith(fakeBridge.call, 'createAnnotation', { msg: ann, tag: ann.$tag, }); diff --git a/src/sidebar/services/frame-sync.js b/src/sidebar/services/frame-sync.js index 1c4dbf8cc84..a676d1fcfe8 100644 --- a/src/sidebar/services/frame-sync.js +++ b/src/sidebar/services/frame-sync.js @@ -144,7 +144,7 @@ export class FrameSyncService { */ this._setupSyncFromGuests = () => { // A new annotation, note or highlight was created in the frame - this._guestRPC.on('beforeCreateAnnotation', event => { + this._guestRPC.on('createAnnotation', event => { const annot = Object.assign({}, event.msg, { $tag: event.tag }); // If user is not logged in, we can't really create a meaningful highlight // or annotation. Instead, we need to open the sidebar, show an error, diff --git a/src/sidebar/services/test/frame-sync-test.js b/src/sidebar/services/test/frame-sync-test.js index 8e4815726c6..0378372506a 100644 --- a/src/sidebar/services/test/frame-sync-test.js +++ b/src/sidebar/services/test/frame-sync-test.js @@ -316,7 +316,7 @@ describe('FrameSyncService', () => { fakeStore.isLoggedIn.returns(true); const ann = { target: [] }; - guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann }); + guestBridge().emit('createAnnotation', { tag: 't1', msg: ann }); assert.calledWith( fakeAnnotationsService.create, @@ -337,28 +337,28 @@ describe('FrameSyncService', () => { it('should not create an annotation in the sidebar', () => { const ann = { target: [] }; - guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann }); + guestBridge().emit('createAnnotation', { tag: 't1', msg: ann }); assert.notCalled(fakeAnnotationsService.create); }); it('should open the sidebar', () => { const ann = { target: [] }; - guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann }); + guestBridge().emit('createAnnotation', { tag: 't1', msg: ann }); assert.calledWith(hostBridge().call, 'openSidebar'); }); it('should open the login prompt panel', () => { const ann = { target: [] }; - guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann }); + guestBridge().emit('createAnnotation', { tag: 't1', msg: ann }); assert.calledWith(fakeStore.openSidebarPanel, 'loginPrompt'); }); it('should send a "deleteAnnotation" message to the frame', () => { const ann = { target: [] }; - guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann }); + guestBridge().emit('createAnnotation', { tag: 't1', msg: ann }); assert.calledWith(guestBridge().call, 'deleteAnnotation'); }); diff --git a/src/types/bridge-events.d.ts b/src/types/bridge-events.d.ts index 932ca4fb001..481918a8c94 100644 --- a/src/types/bridge-events.d.ts +++ b/src/types/bridge-events.d.ts @@ -29,7 +29,7 @@ export type GuestToSidebarEvent = /** * The guest is asking the sidebar to create an annotation. */ - | 'beforeCreateAnnotation' + | 'createAnnotation' /** * The guest is asking the sidebar to relay the message to open the sidebar.