Skip to content

Commit

Permalink
Fix: Ensure pending annotations are destroyed on re-render (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored May 31, 2018
1 parent b74484b commit 1422357
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/controllers/AnnotationModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ class AnnotationModeController extends EventEmitter {

const pageThreads = this.threads[pageNum].all() || [];
pageThreads.forEach((thread, index) => {
// Destroy any pending threads that may exist on re-render
if (isPending(thread.state)) {
this.unregisterThread(thread);
thread.destroy();
return;
}

thread.hideDialog();

// Sets the annotatedElement if the thread was fetched before the
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/__tests__/AnnotationModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ describe('controllers/AnnotationModeController', () => {
});

it('should render the annotations on every page', () => {
sandbox.stub(util, 'isPending').returns(false);
controller.threads = {
// eslint-disable-next-line new-cap
1: new rbush(),
Expand All @@ -506,9 +507,24 @@ describe('controllers/AnnotationModeController', () => {

stubs.threadMock.expects('hideDialog').once();
stubs.threadMock.expects('show').once();
stubs.threadMock.expects('destroy').never();
controller.renderPage(1);
expect(stubs.thread.annotatedElement).to.equal('el');
});

it('should destroy any pending annotations on re-render', () => {
sandbox.stub(util, 'isPending').returns(true);
controller.threads = {
// eslint-disable-next-line new-cap
1: new rbush()
};
controller.threads[1].insert(stubs.thread);

stubs.threadMock.expects('hideDialog').never();
stubs.threadMock.expects('show').never();
stubs.threadMock.expects('destroy').once();
controller.renderPage(1);
});
});

describe('destroyPendingThreads()', () => {
Expand Down

0 comments on commit 1422357

Please sign in to comment.