2019-06-20 21:19:08 +00:00
|
|
|
'use strict'
|
|
|
|
|
2019-06-16 20:19:06 +00:00
|
|
|
class Event {
|
2019-06-20 21:19:08 +00:00
|
|
|
constructor () {
|
|
|
|
this.listeners = []
|
|
|
|
}
|
|
|
|
|
|
|
|
addListener (callback) {
|
|
|
|
this.listeners.push(callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
removeListener (callback) {
|
|
|
|
const index = this.listeners.indexOf(callback)
|
|
|
|
if (index !== -1) {
|
|
|
|
this.listeners.splice(index, 1)
|
2019-06-16 20:19:06 +00:00
|
|
|
}
|
2019-06-20 21:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit (...args) {
|
|
|
|
for (const listener of this.listeners) {
|
|
|
|
listener(...args)
|
2019-06-16 20:19:06 +00:00
|
|
|
}
|
2019-06-20 21:19:08 +00:00
|
|
|
}
|
2019-06-16 20:19:06 +00:00
|
|
|
}
|
2019-06-20 21:19:08 +00:00
|
|
|
|
|
|
|
module.exports = Event
|