Skip to content

Commit

Permalink
fix: hoisting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Mar 19, 2021
1 parent 37b3de8 commit 24dd59a
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/controls/TransformControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ class TransformControls extends Object3D {
this.add(this._gizmo)
this.add(this._plane)

// Defined getter, setter and store for a property
const defineProperty = <TValue>(propName: string, defaultValue: TValue): void => {
Object.defineProperty(this, propName, {
get: function () {
return this[propName]
},

set: function (value) {
if (this[propName] !== value) {
this[propName] = value
this._plane[propName] = value
this._gizmo[propName] = value

this.dispatchEvent({ type: `${propName}-changed`, value })
this.dispatchEvent(this.changeEvent)
}
},
})
// @ts-ignore
this._plane[propName] = defaultValue
// @ts-ignore
this._gizmo[propName] = defaultValue
}

defineProperty('camera', this._camera)
defineProperty('object', this._object)
defineProperty('enabled', this._enabled)
Expand Down Expand Up @@ -150,30 +174,6 @@ class TransformControls extends Object3D {
domElement.addEventListener('pointermove', this.onPointerHover)
this.domElement.ownerDocument.addEventListener('pointerup', this.onPointerUp)
}

// Defined getter, setter and store for a property
const defineProperty = <TValue>(propName: string, defaultValue: TValue): void => {
Object.defineProperty(this, propName, {
get: function () {
return this[propName]
},

set: function (value) {
if (this[propName] !== value) {
this[propName] = value
this._plane[propName] = value
this._gizmo[propName] = value

this.dispatchEvent({ type: `${propName}-changed`, value })
this.dispatchEvent(this.changeEvent)
}
},
})
// @ts-ignore
this._plane[propName] = defaultValue
// @ts-ignore
this._gizmo[propName] = defaultValue
}
}

private intersectObjectWithRay = (
Expand Down

0 comments on commit 24dd59a

Please sign in to comment.