Skip to content

Commit

Permalink
Fix: scale being unbound when annotating (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh-Ng authored Aug 11, 2017
1 parent 9e5489d commit 289c645
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
10 changes: 4 additions & 6 deletions src/lib/annotations/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Annotator extends EventEmitter {

this.unbindDOMListeners();
this.unbindCustomListenersOnService();
this.removeListener('scaleAnnotations', this.scaleAnnotations);
}

/**
Expand Down Expand Up @@ -384,6 +385,7 @@ class Annotator extends EventEmitter {
this.threads = {};
this.bindDOMListeners();
this.bindCustomListenersOnService(this.annotationService);
this.addListener('scaleAnnotations', this.scaleAnnotations);
}

/**
Expand Down Expand Up @@ -420,9 +422,7 @@ class Annotator extends EventEmitter {
*
* @return {void}
*/
bindDOMListeners() {
this.addListener('scaleAnnotations', this.scaleAnnotations);
}
bindDOMListeners() {}

/**
* Unbinds DOM event listeners. Can be overridden by any annotator that
Expand All @@ -432,9 +432,7 @@ class Annotator extends EventEmitter {
* @protected
* @return {void}
*/
unbindDOMListeners() {
this.removeListener('scaleAnnotations', this.scaleAnnotations);
}
unbindDOMListeners() {}

/**
* Binds custom event listeners for the Annotation Service.
Expand Down
19 changes: 3 additions & 16 deletions src/lib/annotations/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ describe('lib/annotations/Annotator', () => {
const unbindCustomStub = sandbox.stub(annotator, 'unbindCustomListenersOnThread');
const unbindDOMStub = sandbox.stub(annotator, 'unbindDOMListeners');
const unbindCustomListenersOnService = sandbox.stub(annotator, 'unbindCustomListenersOnService');
const unbindScaleListener = sandbox.stub(annotator, 'removeListener');

annotator.destroy();

expect(unbindCustomStub).to.be.calledWith(stubs.thread);
expect(unbindDOMStub).to.be.called;
expect(unbindCustomListenersOnService).to.be.called;
expect(unbindScaleListener).to.be.calledWith('scaleAnnotations', sinon.match.func);
});
});

Expand Down Expand Up @@ -166,6 +168,7 @@ describe('lib/annotations/Annotator', () => {
expect(Object.keys(annotator.threads).length === 0).to.be.true;
expect(annotator.bindDOMListeners).to.be.called;
expect(annotator.bindCustomListenersOnService).to.be.called;
expect(annotator.addListener).to.be.calledWith('scaleAnnotations', sinon.match.func);
});
});

Expand Down Expand Up @@ -384,22 +387,6 @@ describe('lib/annotations/Annotator', () => {
});
});

describe('bindDOMListeners()', () => {
it('should add a listener for scaling the annotator', () => {
sandbox.stub(annotator, 'addListener');
annotator.bindDOMListeners();
expect(annotator.addListener).to.be.calledWith('scaleAnnotations', sinon.match.func);
});
});

describe('unbindDOMListeners()', () => {
it('should add a listener for scaling the annotator', () => {
sandbox.stub(annotator, 'removeListener');
annotator.unbindDOMListeners();
expect(annotator.removeListener).to.be.calledWith('scaleAnnotations', sinon.match.func);
});
});

describe('bindCustomListenersOnService()', () => {
it('should do nothing if the service does not exist', () => {
annotator.annotationService = {
Expand Down

0 comments on commit 289c645

Please sign in to comment.