From 90a9642b0c1520d7ca38a793562e0b4f263c938d Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Fri, 13 Apr 2018 16:08:37 -0700 Subject: [PATCH] Chore: unregister pending threads on destroy --- src/controllers/AnnotationModeController.js | 6 +----- .../__tests__/AnnotationModeController-test.js | 8 +++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/controllers/AnnotationModeController.js b/src/controllers/AnnotationModeController.js index 6c9cb1a0f..cbb784b9a 100644 --- a/src/controllers/AnnotationModeController.js +++ b/src/controllers/AnnotationModeController.js @@ -443,12 +443,8 @@ class AnnotationModeController extends EventEmitter { const pageThreads = this.threads[pageNum].all() || []; pageThreads.forEach((thread) => { if (isPending(thread.state)) { + this.unregisterThread(thread); hadPendingThreads = true; - - /* eslint-disable no-console */ - console.error('Pending annotation thread destroyed', thread.threadNumber); - /* eslint-enable no-console */ - thread.destroy(); } else if (thread.isDialogVisible()) { thread.hideDialog(); diff --git a/src/controllers/__tests__/AnnotationModeController-test.js b/src/controllers/__tests__/AnnotationModeController-test.js index e036ebee6..215aca52a 100644 --- a/src/controllers/__tests__/AnnotationModeController-test.js +++ b/src/controllers/__tests__/AnnotationModeController-test.js @@ -512,7 +512,7 @@ describe('controllers/AnnotationModeController', () => { beforeEach(() => { stubs.isPending = sandbox.stub(util, 'isPending').returns(false); stubs.isPending.withArgs(STATES.pending).returns(true); - + sandbox.stub(controller, 'unregisterThread'); controller.registerThread(stubs.thread); }); @@ -520,6 +520,8 @@ describe('controllers/AnnotationModeController', () => { stubs.threadMock.expects('destroy'); const destroyed = controller.destroyPendingThreads(); expect(destroyed).to.be.true; + expect(controller.unregisterThread).to.be.called; + expect(controller.unregisterThread).to.be.called; }); it('should not destroy and return false if there are no threads', () => { @@ -528,6 +530,7 @@ describe('controllers/AnnotationModeController', () => { stubs.isPending.returns(false); const destroyed = controller.destroyPendingThreads(); expect(destroyed).to.be.false; + expect(controller.unregisterThread).to.not.be.called; }); it('should not destroy and return false if the threads are not pending', () => { @@ -537,6 +540,7 @@ describe('controllers/AnnotationModeController', () => { stubs.threadMock.expects('hideDialog').never(); const destroyed = controller.destroyPendingThreads(); expect(destroyed).to.be.false; + expect(controller.unregisterThread).to.not.be.called; }); it('should hide non-pending thread dialogs that are visible', () => { @@ -546,6 +550,7 @@ describe('controllers/AnnotationModeController', () => { stubs.threadMock.expects('hideDialog'); const destroyed = controller.destroyPendingThreads(); expect(destroyed).to.be.false; + expect(controller.unregisterThread).to.not.be.called; }); it('should destroy only pending threads, and return true', () => { @@ -568,6 +573,7 @@ describe('controllers/AnnotationModeController', () => { const destroyed = controller.destroyPendingThreads(); expect(destroyed).to.be.true; + expect(controller.unregisterThread).to.be.called; }); });