Skip to content

Commit

Permalink
[cleanup] Remove unneeded iife in addHelper (#753)
Browse files Browse the repository at this point in the history
* Remove unneeded iife in addHelper

* Use const to be consistent in this file
  • Loading branch information
vincentfretin authored Aug 29, 2024
1 parent 1101fbe commit fb68ae9
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,36 +96,34 @@ Inspector.prototype = {
Events.emit('objectremove', object);
},

addHelper: (function () {
return function (object) {
let helper;

if (object instanceof THREE.Camera) {
this.cameraHelper = helper = new THREE.CameraHelper(object);
} else if (object instanceof THREE.PointLight) {
helper = new THREE.PointLightHelper(object, 1);
} else if (object instanceof THREE.DirectionalLight) {
helper = new THREE.DirectionalLightHelper(object, 1);
} else if (object instanceof THREE.SpotLight) {
helper = new THREE.SpotLightHelper(object, 1);
} else if (object instanceof THREE.HemisphereLight) {
helper = new THREE.HemisphereLightHelper(object, 1);
} else if (object instanceof THREE.SkinnedMesh) {
helper = new THREE.SkeletonHelper(object);
} else {
// no helper for this object type
return;
}
addHelper: function (object) {
let helper;

if (object instanceof THREE.Camera) {
this.cameraHelper = helper = new THREE.CameraHelper(object);
} else if (object instanceof THREE.PointLight) {
helper = new THREE.PointLightHelper(object, 1);
} else if (object instanceof THREE.DirectionalLight) {
helper = new THREE.DirectionalLightHelper(object, 1);
} else if (object instanceof THREE.SpotLight) {
helper = new THREE.SpotLightHelper(object, 1);
} else if (object instanceof THREE.HemisphereLight) {
helper = new THREE.HemisphereLightHelper(object, 1);
} else if (object instanceof THREE.SkinnedMesh) {
helper = new THREE.SkeletonHelper(object);
} else {
// no helper for this object type
return;
}

helper.visible = false;
this.sceneHelpers.add(helper);
this.helpers[object.uuid] = helper;
// SkeletonHelper doesn't have an update method
if (helper.update) {
helper.update();
}
};
})(),
helper.visible = false;
this.sceneHelpers.add(helper);
this.helpers[object.uuid] = helper;
// SkeletonHelper doesn't have an update method
if (helper.update) {
helper.update();
}
},

removeHelpers: function (object) {
object.traverse((node) => {
Expand All @@ -152,7 +150,7 @@ Inspector.prototype = {
}

// Update helper visibilities.
for (let id in this.helpers) {
for (const id in this.helpers) {
this.helpers[id].visible = false;
}

Expand All @@ -172,7 +170,7 @@ Inspector.prototype = {
initEvents: function () {
window.addEventListener('keydown', (evt) => {
// Alt + Ctrl + i: Shorcut to toggle the inspector
var shortcutPressed =
const shortcutPressed =
evt.keyCode === 73 &&
((evt.ctrlKey && evt.altKey) || evt.getModifierState('AltGraph'));
if (shortcutPressed) {
Expand All @@ -196,7 +194,7 @@ Inspector.prototype = {
});

document.addEventListener('child-detached', (event) => {
var entity = event.detail.el;
const entity = event.detail.el;
AFRAME.INSPECTOR.removeObject(entity.object3D);
});
},
Expand Down

0 comments on commit fb68ae9

Please sign in to comment.