Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventDispatcher converted to es6 #20943

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/core/EventDispatcher.js
Expand Up @@ -2,11 +2,9 @@
* https://github.com/mrdoob/eventdispatcher.js/
*/

function EventDispatcher() {}
class EventDispatcher {

Object.assign( EventDispatcher.prototype, {

addEventListener: function ( type, listener ) {
addEventListener( type, listener ) {

if ( this._listeners === undefined ) this._listeners = {};

Expand All @@ -24,19 +22,18 @@ Object.assign( EventDispatcher.prototype, {

}

},
}

hasEventListener: function ( type, listener ) {
hasEventListener( type, listener ) {

if ( this._listeners === undefined ) return false;

const listeners = this._listeners;

return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;

},
}

removeEventListener: function ( type, listener ) {
removeEventListener( type, listener ) {

if ( this._listeners === undefined ) return;

Expand All @@ -55,9 +52,9 @@ Object.assign( EventDispatcher.prototype, {

}

},
}

dispatchEvent: function ( event ) {
dispatchEvent( event ) {

if ( this._listeners === undefined ) return;

Expand All @@ -81,7 +78,7 @@ Object.assign( EventDispatcher.prototype, {

}

} );
}


export { EventDispatcher };