Skip to content

Commit

Permalink
Chore: Remove autobind from 3d viewers (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinHoldstock authored Nov 22, 2017
1 parent a2b93fd commit 411f319
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
21 changes: 19 additions & 2 deletions src/lib/viewers/box3d/Box3DViewer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import autobind from 'autobind-decorator';
import BaseViewer from '../BaseViewer';
import fullscreen from '../../Fullscreen';
import Box3DControls from './Box3DControls';
Expand Down Expand Up @@ -31,7 +30,6 @@ const CLASS_VR_ENABLED = 'vr-enabled';
* Box3DViewer
* This is the entry point for Box3D Preview Base
*/
@autobind
class Box3DViewer extends BaseViewer {
/** @property {Box3DRenderer} - Box3DRenderer instance. Renders the 3D scene */
renderer;
Expand All @@ -42,6 +40,25 @@ class Box3DViewer extends BaseViewer {
/** @property {Notification} - Used to notify users of WebGL context issues */
contextNotification;

/** @inheritdoc */
constructor(options) {
super(options);

this.handleToggleVr = this.handleToggleVr.bind(this);
this.handleReset = this.handleReset.bind(this);
this.handleSceneLoaded = this.handleSceneLoaded.bind(this);
this.handleShowVrButton = this.handleShowVrButton.bind(this);
this.handleError = this.handleError.bind(this);
this.handleContextRestored = this.handleContextRestored.bind(this);
this.handleContextLost = this.handleContextLost.bind(this);

this.onVrPresentChange = this.onVrPresentChange.bind(this);
this.handleEnableVr = this.handleEnableVr.bind(this);
this.handleDisableVr = this.handleDisableVr.bind(this);

this.postLoad = this.postLoad.bind(this);
}

/**
* @inheritdoc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/box3d/__tests__/Box3DViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ describe('lib/viewers/box3d/Box3DViewer', () => {
});

it('should call detachEventHandlers', () => {
const detachHandlers = sandbox.stub(box3d, 'detachEventHandlers', () => {});
const detachHandlers = sandbox.stub(box3d, 'detachEventHandlers');
box3d.handleContextRestored();
expect(detachHandlers).to.be.called;
});
Expand Down
20 changes: 18 additions & 2 deletions src/lib/viewers/box3d/model3d/Model3DViewer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import autobind from 'autobind-decorator';
import Box3DViewer from '../Box3DViewer';
import Model3DControls from './Model3DControls';
import Model3DRenderer from './Model3DRenderer';
Expand Down Expand Up @@ -28,7 +27,6 @@ const LOAD_TIMEOUT = 180000; // 3 minutes
* Model3d
* This is the entry point for the model3d preview.
*/
@autobind
class Model3DViewer extends Box3DViewer {
/** @property {Object[]} - List of Box3D instances added to the scene */
instances = [];
Expand All @@ -39,6 +37,24 @@ class Model3DViewer extends Box3DViewer {
forward: null
};

/** @inheritdoc */
constructor(option) {
super(option);

this.handleRotateOnAxis = this.handleRotateOnAxis.bind(this);
this.handleSelectAnimationClip = this.handleSelectAnimationClip.bind(this);
this.handleSetCameraProjection = this.handleSetCameraProjection.bind(this);
this.handleSetRenderMode = this.handleSetRenderMode.bind(this);
this.handleShowSkeletons = this.handleShowSkeletons.bind(this);
this.handleShowWireframes = this.handleShowWireframes.bind(this);
this.handleShowGrid = this.handleShowGrid.bind(this);
this.handleToggleAnimation = this.handleToggleAnimation.bind(this);
this.handleToggleHelpers = this.handleToggleHelpers.bind(this);
this.handleCanvasClick = this.handleCanvasClick.bind(this);

this.onMetadataError = this.onMetadataError.bind(this);
}

/**
* @inheritdoc
*/
Expand Down
22 changes: 12 additions & 10 deletions src/lib/viewers/box3d/video360/Video360Viewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global BoxSDK */
import autobind from 'autobind-decorator';
import fullscreen from '../../../Fullscreen';
import DashViewer from '../../media/DashViewer';
import Video360Controls from './Video360Controls';
Expand Down Expand Up @@ -36,6 +35,17 @@ class Video360Viewer extends DashViewer {
/** @property {Box3D.Components.SkyboxRenderer} - The component for rendering the video as 360 degree (on a skybox) */
skybox;

/** @inheritdoc */
constructor(options) {
super(options);

this.create360Environment = this.create360Environment.bind(this);
this.handleToggleVr = this.handleToggleVr.bind(this);
this.handleShowVrButton = this.handleShowVrButton.bind(this);
this.onCanvasMouseDown = this.onCanvasMouseDown.bind(this);
this.onCanvasMouseUp = this.onCanvasMouseUp.bind(this);
}

/** @inheritdoc */
setup() {
this.fileLoadingIcon = ICON_FILE_MEDIA;
Expand Down Expand Up @@ -103,7 +113,6 @@ class Video360Viewer extends DashViewer {
*
* @inheritdoc
*/
@autobind
loadeddataHandler() {
const { token, apiHost } = this.options;
this.renderer = new Video360Renderer(this.mediaContainerEl, new BoxSDK({ token, apiBase: apiHost }));
Expand Down Expand Up @@ -174,7 +183,6 @@ class Video360Viewer extends DashViewer {
/**
* @inheritdoc
*/
@autobind
resize() {
super.resize();
if (this.renderer) {
Expand All @@ -189,7 +197,6 @@ class Video360Viewer extends DashViewer {
* @private
* @return {void}
*/
@autobind
create360Environment() {
this.skybox = this.renderer.getScene().getComponentByScriptId('skybox_renderer');

Expand Down Expand Up @@ -220,7 +227,6 @@ class Video360Viewer extends DashViewer {
/**
* @inheritdoc
*/
@autobind
toggleFullscreen() {
fullscreen.toggle(this.wrapperEl);
}
Expand All @@ -230,7 +236,6 @@ class Video360Viewer extends DashViewer {
*
* @return {void}
*/
@autobind
handleToggleVr() {
this.renderer.toggleVr();

Expand All @@ -251,7 +256,6 @@ class Video360Viewer extends DashViewer {
*
* @return {void}
*/
@autobind
handleShowVrButton() {
this.controls.showVrButton();
}
Expand All @@ -261,7 +265,6 @@ class Video360Viewer extends DashViewer {
*
* @return {void}
*/
@autobind
onCanvasMouseDown() {
this.renderer.getBox3D().once('mouseUp', this.onCanvasMouseUp);
}
Expand All @@ -271,11 +274,10 @@ class Video360Viewer extends DashViewer {
*
* @return {void}
*/
@autobind
onCanvasMouseUp() {
const input = this.renderer.getInputController();
// Make sure the mouse hasn't moved (within mouse/touch buffer drag allowance)
if (!input.getPreviousMouseDragState() && !input.getPreviousTouchDragState()) {
if (input && !input.getPreviousMouseDragState() && !input.getPreviousTouchDragState()) {
this.togglePlay();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ describe('lib/viewers/box3d/video360/Video360Viewer', () => {
viewer.renderer = {
getInputController: sandbox.stub().returns(input)
};

sandbox.stub(viewer, 'togglePlay');
});

Expand Down

0 comments on commit 411f319

Please sign in to comment.