Skip to content

Commit

Permalink
Fix: BaseViewer debounced resize handler binding (#509)
Browse files Browse the repository at this point in the history
Context was bound to the fetch resize handler function instead of the actual handler
  • Loading branch information
tonyjin authored Nov 22, 2017
1 parent 2e71743 commit 32f3c9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BaseViewer extends EventEmitter {
// Bind context for callbacks
this.resetLoadTimeout = this.resetLoadTimeout.bind(this);
this.preventDefault = this.preventDefault.bind(this);
this.debouncedResizeHandler = this.debouncedResizeHandler.bind(this);
this.debouncedResizeHandler = this.getResizeHandler().bind(this);
this.handleAssetError = this.handleAssetError.bind(this);
this.toggleFullscreen = this.toggleFullscreen.bind(this);
this.onFullscreenToggled = this.onFullscreenToggled.bind(this);
Expand Down Expand Up @@ -209,7 +209,7 @@ class BaseViewer extends EventEmitter {
* @private
* @return {Function} debounced resize handler
*/
debouncedResizeHandler() {
getResizeHandler() {
return debounce(() => {
this.resize();
}, RESIZE_WAIT_TIME_IN_MILLIS);
Expand Down
9 changes: 4 additions & 5 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ describe('lib/viewers/BaseViewer', () => {
});
});

describe('debouncedResizeHandler()', () => {
describe('getResizeHandler()', () => {
it('should return a resize handler', () => {
expect(base.debouncedResizeHandler()).to.be.a.function;
expect(base.getResizeHandler()).to.be.a.function;
});
});

Expand Down Expand Up @@ -288,15 +288,14 @@ describe('lib/viewers/BaseViewer', () => {
stubs.baseAddListener = sandbox.spy(base, 'addListener');
stubs.documentAddEventListener = sandbox.stub(document.defaultView, 'addEventListener');
sandbox.stub(base, 'initAnnotations');


});

it('should append common event listeners', () => {
base.addCommonListeners();

expect(stubs.fullscreenAddListener).to.be.calledWith('enter', sinon.match.func);
expect(stubs.fullscreenAddListener).to.be.calledWith('exit', sinon.match.func);
expect(stubs.documentAddEventListener).to.be.calledWith('resize', base.debouncedResizeHandler);
expect(stubs.documentAddEventListener).to.be.calledWith('resize', sinon.match.func);
expect(stubs.baseAddListener).to.be.calledWith('load', sinon.match.func);
});

Expand Down

0 comments on commit 32f3c9a

Please sign in to comment.