Skip to content

Commit

Permalink
Rename beforeCreateAnnotation to createAnnotation
Browse files Browse the repository at this point in the history
This is the event that creates the annotation, so it is better to name
it in a more obvious way.

Context:
#3829 (comment)
  • Loading branch information
esanzgar committed Oct 19, 2021
1 parent 5707862 commit 05d47ef
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/annotator/annotation-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class AnnotationSync {
if (annotation.$tag) {
return;
}
this._sidebar.call('beforeCreateAnnotation', this._format(annotation));
this._sidebar.call('createAnnotation', this._format(annotation));
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/annotator/test/annotation-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' };
Expand All @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar/services/frame-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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,
Expand Down
16 changes: 8 additions & 8 deletions src/sidebar/services/test/frame-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,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(hostBridge().call, 'showHighlights');
});
Expand All @@ -326,7 +326,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,
Expand All @@ -342,7 +342,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(hostBridge().call, 'openSidebar');
});
Expand All @@ -352,7 +352,7 @@ describe('FrameSyncService', () => {
fakeStore.isLoggedIn.returns(true);
const ann = { $highlight: true, target: [] };

guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });

assert.neverCalledWith(hostBridge().call, 'openSidebar');
});
Expand All @@ -367,28 +367,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');
});
Expand Down
2 changes: 1 addition & 1 deletion src/types/bridge-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 the host to close the sidebar.
Expand Down

0 comments on commit 05d47ef

Please sign in to comment.