1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

make event listener static

This commit is contained in:
Sebastian Gerske 2018-11-23 11:47:39 +01:00
parent df475b6958
commit f37a1cc1c6
2 changed files with 9 additions and 12 deletions

View File

@ -2,11 +2,9 @@ import Event from "./Event"
export default class EventListener {
private static events: Event[] = []
public subscribe(contractName: string,
eventName: string,
filter: any): Event {
public static subscribe(contractName: string,
eventName: string,
filter: any): Event {
const event = new Event(contractName, eventName, filter)
EventListener.events.push(event)
@ -14,7 +12,7 @@ export default class EventListener {
return event
}
public unsubscribe(event): boolean {
public static unsubscribe(event): boolean {
EventListener.events = EventListener.events.splice(
EventListener.events.findIndex((e) => e === event),
@ -22,4 +20,6 @@ export default class EventListener {
return true
}
private static events: Event[] = []
}

View File

@ -28,10 +28,9 @@ describe("EventListener", () => {
it("should subscribe to an event", (done) => {
const eventListener = new EventListener()
const acc = accounts[1]
const event = eventListener.subscribe("OceanToken",
const event = EventListener.subscribe("OceanToken",
"Transfer",
{
to: acc.getId(),
@ -55,13 +54,11 @@ describe("EventListener", () => {
it("should subscribe to an event", (done) => {
const eventListener = new EventListener()
const event = eventListener.subscribe("OceanToken",
const event = EventListener.subscribe("OceanToken",
"Transfer",
{})
const unsubscribed = eventListener.unsubscribe(event)
const unsubscribed = EventListener.unsubscribe(event)
assert(unsubscribed)
done()