Skip to content

Commit

Permalink
Chore: Remove autobind from DocFindBar (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjin authored Nov 22, 2017
1 parent cd3c67e commit 2a750e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
13 changes: 9 additions & 4 deletions src/lib/viewers/doc/DocFindBar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import autobind from 'autobind-decorator';
import EventEmitter from 'events';
import { decodeKeydown } from '../../util';
import { CLASS_HIDDEN } from '../../constants';
Expand All @@ -13,7 +12,6 @@ const FIND_MATCH_FOUND = 0;
const FIND_MATCH_NOT_FOUND = 1;
const FIND_MATCH_PENDING = 3;

@autobind
class DocFindBar extends EventEmitter {
/**
* [constructor]
Expand All @@ -36,9 +34,16 @@ class DocFindBar extends EventEmitter {
throw new Error('DocFindBar cannot be used without a PDFFindController instance.');
}

// Bind context for callbacks
this.displayFindBarHandler = this.displayFindBarHandler.bind(this);
this.findFieldHandler = this.findFieldHandler.bind(this);
this.barKeyDownHandler = this.barKeyDownHandler.bind(this);
this.findNextHandler = this.findNextHandler.bind(this);
this.findPreviousHandler = this.findPreviousHandler.bind(this);

// overriding some find controller methods to update match count
this.findController.updateUIState = this.updateUIState;
this.findController.updateUIResultsCount = this.updateUIResultsCount;
this.findController.updateUIState = this.updateUIState.bind(this);
this.findController.updateUIResultsCount = this.updateUIResultsCount.bind(this);

// Default hides find bar on load
this.bar.classList.add(CLASS_HIDDEN);
Expand Down
23 changes: 0 additions & 23 deletions src/lib/viewers/doc/__tests__/DocFindBar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ describe('lib/viewers/doc/DocFindBar', () => {
expect(docFindBar.canDownload).to.be.true;
});

it('should override find controller methods', () => {
expect(docFindBar.findController.updateUIState).to.equal(docFindBar.updateUIState);
expect(docFindBar.findController.updateUIResultsCount).to.equal(docFindBar.updateUIResultsCount);
});

it('should throw an error if there is no findController', () => {
docFindBar.destroy();
findController = null;
Expand All @@ -81,24 +76,6 @@ describe('lib/viewers/doc/DocFindBar', () => {
expect(e.message).to.equal('DocFindBar cannot be used without a PDFFindController instance.');
}
});

it('should create elements and bind DOM Listeners', () => {
const proto = DocFindBar.prototype;
DocFindBar.prototype = {
createFindField: sandbox.stub(),
createFindButtons: sandbox.stub(),
bindDOMListeners: sandbox.stub()
};

let docFindBar2 = new DocFindBar(findBarEl, findController);
expect(DocFindBar.prototype.createFindField).to.be.called;
expect(DocFindBar.prototype.createFindButtons).to.be.called;
expect(DocFindBar.prototype.bindDOMListeners).to.be.called;
expect(docFindBar2 instanceof DocFindBar).to.be.true;

DocFindBar.prototype = proto;
docFindBar2 = undefined;
});
});

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

0 comments on commit 2a750e7

Please sign in to comment.