diff options
Diffstat (limited to 'src/types/EventTarget.js')
-rw-r--r-- | src/types/EventTarget.js | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/types/EventTarget.js b/src/types/EventTarget.js index 5a005fd..3d755bf 100644 --- a/src/types/EventTarget.js +++ b/src/types/EventTarget.js @@ -2,57 +2,79 @@ import { dispatch, off, on } from '../modules/core/event.js' import Base from './Base.js' export default class EventTarget extends Base { - constructor ({ events = {} } = {}) { + + constructor ( { events = {} } = {} ) { + super() this.events = events + } addEventListener () {} - dispatch (event, data) { - return dispatch(this, event, data) + dispatch ( event, data ) { + + return dispatch( this, event, data ) + } - dispatchEvent (event) { + dispatchEvent ( event ) { + const bag = this.getEventHolder().events - if (!bag) return true + if ( !bag ) return true const events = bag[event.type] - for (let i in events) { - for (let j in events[i]) { - events[i][j](event) + for ( let i in events ) { + + for ( let j in events[i] ) { + + events[i][j]( event ) + } + } return !event.defaultPrevented + } // Fire given event - fire (event, data) { - this.dispatch(event, data) + fire ( event, data ) { + + this.dispatch( event, data ) return this + } getEventHolder () { + return this + } getEventTarget () { + return this + } // Unbind event from listener - off (event, listener) { - off(this, event, listener) + off ( event, listener ) { + + off( this, event, listener ) return this + } // Bind given event to listener - on (event, listener, binding, options) { - on(this, event, listener, binding, options) + on ( event, listener, binding, options ) { + + on( this, event, listener, binding, options ) return this + } removeEventListener () {} + } |