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 15, 2021
1 parent 545ce16 commit e2e347d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/annotator/annotation-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class AnnotationSync {
if (annotation.$tag) {
return;
}
this.bridge.call('beforeCreateAnnotation', this._format(annotation));
this.bridge.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 @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/sidebar/services/test/frame-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
});
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 open the sidebar.
Expand Down

0 comments on commit e2e347d

Please sign in to comment.