Skip to content

Commit

Permalink
Fix: Only registering thread with controller on save (#22)
Browse files Browse the repository at this point in the history
- Annotations should only be registered with the controller on save when
  the location is finalized. They no longer need to be saved in the
  annotator threadMap, therefore we no longer care when the location was
  initially assigned
  • Loading branch information
pramodsum committed Nov 8, 2017
1 parent ca54d5e commit ff75bf1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/controllers/DrawingModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,13 @@ class DrawingModeController extends AnnotationModeController {
handleThreadEvents(thread, data = {}) {
const { eventData } = data;
switch (data.event) {
case 'locationassigned':
// Register the thread to the threadmap when a starting location is assigned. Should only occur once.
this.registerThread(thread);
break;
case 'softcommit':
// Save the original thread, create a new thread and
// start drawing at the location indicating the page change
this.currentThread = undefined;
thread.saveAnnotation(TYPES.draw);
this.registerThread(thread);

this.unbindListeners();
this.bindListeners();

Expand Down
11 changes: 3 additions & 8 deletions src/controllers/__tests__/DrawingModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,17 @@ describe('controllers/DrawingModeController', () => {
stubs.thread.dialog = {};
});

it('should add thread to map on locationassigned', () => {
sandbox.stub(controller, 'registerThread');
controller.handleThreadEvents(stubs.thread, {
event: 'locationassigned'
});
expect(controller.registerThread).to.be.called;
});

it('should restart mode listeners from the thread on softcommit', () => {
sandbox.stub(controller, 'unbindListeners');
sandbox.stub(controller, 'bindListeners');
sandbox.stub(controller, 'registerThread');
controller.handleThreadEvents(stubs.thread, {
event: 'softcommit'
});
expect(controller.unbindListeners).to.be.called;
expect(controller.bindListeners).to.be.called;
expect(stubs.thread.saveAnnotation).to.be.called;
expect(controller.registerThread).to.be.called;
expect(stubs.thread.handleStart).to.not.be.called;
});

Expand Down Expand Up @@ -325,6 +319,7 @@ describe('controllers/DrawingModeController', () => {
location: 'not empty'
}
};
sandbox.stub(controller, 'registerThread');
sandbox.stub(controller, 'unbindListeners');
sandbox.stub(controller, 'bindListeners', () => {
controller.currentThread = thread2;
Expand Down
1 change: 0 additions & 1 deletion src/doc/DocDrawingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class DocDrawingThread extends DrawingThread {
dimensions: location.dimensions
};
this.checkAndHandleScaleUpdate();
this.emit('locationassigned');
}

this.drawingFlag = DRAW_STATES.drawing;
Expand Down
1 change: 0 additions & 1 deletion src/drawing/DrawingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class DrawingThread extends AnnotationThread {
// Recreate stored paths
if (this.location && this.location.paths) {
this.setBoundary();
this.emit('locationassigned');

this.location.paths.forEach((drawingPathData) => {
const pathInstance = new DrawingPath(drawingPathData);
Expand Down

0 comments on commit ff75bf1

Please sign in to comment.