Skip to content

Commit

Permalink
Fix: annotation handler rebinding (#294)
Browse files Browse the repository at this point in the history
* Fix: annotation handler rebinding
* Fix: remove drawing annotation type
  • Loading branch information
Minh-Ng authored Aug 11, 2017
1 parent 289c645 commit 2dc0200
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
14 changes: 5 additions & 9 deletions src/lib/annotations/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,16 +545,15 @@ class Annotator extends EventEmitter {
* @return {void}
*/
bindPointModeListeners() {
const pointFunc = this.pointClickHandler.bind(this.annotatedElement);
const handlers = [
{
type: 'mousedown',
func: pointFunc,
func: this.pointClickHandler,
eventObj: this.annotatedElement
},
{
type: 'touchstart',
func: pointFunc,
func: this.pointClickHandler,
eventObj: this.annotatedElement
}
];
Expand Down Expand Up @@ -616,26 +615,23 @@ class Annotator extends EventEmitter {
return;
}

const startCallback = drawingThread.handleStart.bind(drawingThread);
const stopCallback = drawingThread.handleStop.bind(drawingThread);
const moveCallback = drawingThread.handleMove.bind(drawingThread);
/* eslint-disable require-jsdoc */
const locationFunction = (event) => this.getLocationFromEvent(event, TYPES.point);
/* eslint-enable require-jsdoc */
const handlers = [
{
type: 'mousemove',
func: annotatorUtil.eventToLocationHandler(locationFunction, moveCallback),
func: annotatorUtil.eventToLocationHandler(locationFunction, drawingThread.handleMove),
eventObj: this.annotatedElement
},
{
type: 'mousedown',
func: annotatorUtil.eventToLocationHandler(locationFunction, startCallback),
func: annotatorUtil.eventToLocationHandler(locationFunction, drawingThread.handleStart),
eventObj: this.annotatedElement
},
{
type: 'mouseup',
func: annotatorUtil.eventToLocationHandler(locationFunction, stopCallback),
func: annotatorUtil.eventToLocationHandler(locationFunction, drawingThread.handleStop),
eventObj: this.annotatedElement
}
];
Expand Down
10 changes: 0 additions & 10 deletions src/lib/annotations/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,8 @@ describe('lib/annotations/Annotator', () => {
it('should bind point mode click handler', () => {
sandbox.stub(annotator.annotatedElement, 'addEventListener');
sandbox.stub(annotator.annotatedElement, 'removeEventListener');
sandbox.stub(annotator.pointClickHandler, 'bind', () => annotator.pointClickHandler);

annotator.bindPointModeListeners();
expect(annotator.pointClickHandler.bind).to.be.called;
expect(annotator.annotatedElement.addEventListener).to.be.calledWith(
'mousedown',
annotator.pointClickHandler
Expand All @@ -508,11 +506,9 @@ describe('lib/annotations/Annotator', () => {
describe('unbindModeListeners()', () => {
it('should unbind point mode click handler', () => {
sandbox.stub(annotator.annotatedElement, 'removeEventListener');
sandbox.stub(annotator.pointClickHandler, 'bind', () => annotator.pointClickHandler);

annotator.bindPointModeListeners();
annotator.unbindModeListeners();
expect(annotator.pointClickHandler.bind).to.be.called;
expect(annotator.annotatedElement.removeEventListener).to.be.calledWith(
'mousedown',
annotator.pointClickHandler
Expand Down Expand Up @@ -656,16 +652,10 @@ describe('lib/annotations/Annotator', () => {
sandbox.stub(annotator.annotatedElement, 'addEventListener');
sandbox.stub(annotator.annotatedElement, 'removeEventListener');
sandbox.stub(annotator, 'isInDrawMode').returns(true);
sandbox.stub(drawingThread.handleStart, 'bind', () => drawingThread.pointClickHandler);
sandbox.stub(drawingThread.handleStop, 'bind', () => drawingThread.pointClickHandler);
sandbox.stub(drawingThread.handleMove, 'bind', () => drawingThread.pointClickHandler);
sandbox.stub(annotatorUtil, 'eventToLocationHandler').returns(locationHandler);

annotator.bindDrawModeListeners(drawingThread, postButtonEl);

expect(drawingThread.handleStart.bind).to.be.called;
expect(drawingThread.handleStop.bind).to.be.called;
expect(drawingThread.handleMove.bind).to.be.called;
expect(annotator.annotatedElement.addEventListener).to.be.calledWith(
sinon.match.string,
locationHandler
Expand Down
4 changes: 4 additions & 0 deletions src/lib/annotations/drawing/DrawingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class DrawingThread extends AnnotationThread {
*/
constructor(data) {
super(data);

this.render = this.render.bind(this);
this.handleStart = this.handleStart.bind(this);
this.handleMove = this.handleMove.bind(this);
this.handleStop = this.handleStop.bind(this);
}

/**
Expand Down

0 comments on commit 2dc0200

Please sign in to comment.