2018-11-23 11:39:16 +01:00
|
|
|
import Event from "./Event"
|
|
|
|
|
|
|
|
export default class EventListener {
|
|
|
|
|
2018-11-23 11:47:39 +01:00
|
|
|
public static subscribe(contractName: string,
|
|
|
|
eventName: string,
|
|
|
|
filter: any): Event {
|
2018-11-23 11:39:16 +01:00
|
|
|
|
|
|
|
const event = new Event(contractName, eventName, filter)
|
|
|
|
EventListener.events.push(event)
|
|
|
|
|
|
|
|
return event
|
|
|
|
}
|
|
|
|
|
2018-11-23 11:47:39 +01:00
|
|
|
public static unsubscribe(event): boolean {
|
2018-11-23 12:40:49 +01:00
|
|
|
event.stopListen()
|
|
|
|
const i = EventListener.events.indexOf(event)
|
|
|
|
if (i > -1) {
|
|
|
|
EventListener.events.splice(i, 1)
|
|
|
|
}
|
2018-11-23 11:39:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2018-11-23 11:47:39 +01:00
|
|
|
|
2018-11-23 12:40:49 +01:00
|
|
|
public static count() {
|
|
|
|
return EventListener.events.length
|
|
|
|
}
|
|
|
|
|
2018-11-23 11:47:39 +01:00
|
|
|
private static events: Event[] = []
|
2018-11-23 11:39:16 +01:00
|
|
|
}
|