Initial project import
This commit is contained in:
78
node_modules/three-stdlib/controls/EventDispatcher.js
generated
vendored
Normal file
78
node_modules/three-stdlib/controls/EventDispatcher.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
class EventDispatcher {
|
||||
constructor() {
|
||||
// not defined in @types/three
|
||||
__publicField(this, "_listeners");
|
||||
}
|
||||
/**
|
||||
* Adds a listener to an event type.
|
||||
* @param type The type of event to listen to.
|
||||
* @param listener The function that gets called when the event is fired.
|
||||
*/
|
||||
addEventListener(type, listener) {
|
||||
if (this._listeners === void 0)
|
||||
this._listeners = {};
|
||||
const listeners = this._listeners;
|
||||
if (listeners[type] === void 0) {
|
||||
listeners[type] = [];
|
||||
}
|
||||
if (listeners[type].indexOf(listener) === -1) {
|
||||
listeners[type].push(listener);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if listener is added to an event type.
|
||||
* @param type The type of event to listen to.
|
||||
* @param listener The function that gets called when the event is fired.
|
||||
*/
|
||||
hasEventListener(type, listener) {
|
||||
if (this._listeners === void 0)
|
||||
return false;
|
||||
const listeners = this._listeners;
|
||||
return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1;
|
||||
}
|
||||
/**
|
||||
* Removes a listener from an event type.
|
||||
* @param type The type of the listener that gets removed.
|
||||
* @param listener The listener function that gets removed.
|
||||
*/
|
||||
removeEventListener(type, listener) {
|
||||
if (this._listeners === void 0)
|
||||
return;
|
||||
const listeners = this._listeners;
|
||||
const listenerArray = listeners[type];
|
||||
if (listenerArray !== void 0) {
|
||||
const index = listenerArray.indexOf(listener);
|
||||
if (index !== -1) {
|
||||
listenerArray.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Fire an event type.
|
||||
* @param event The event that gets fired.
|
||||
*/
|
||||
dispatchEvent(event) {
|
||||
if (this._listeners === void 0)
|
||||
return;
|
||||
const listeners = this._listeners;
|
||||
const listenerArray = listeners[event.type];
|
||||
if (listenerArray !== void 0) {
|
||||
event.target = this;
|
||||
const array = listenerArray.slice(0);
|
||||
for (let i = 0, l = array.length; i < l; i++) {
|
||||
array[i].call(this, event);
|
||||
}
|
||||
event.target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
EventDispatcher
|
||||
};
|
||||
//# sourceMappingURL=EventDispatcher.js.map
|
||||
Reference in New Issue
Block a user