UNPKG

leap-node

Version:

[![codecov](https://codecov.io/gh/leapdao/leap-node/branch/master/graph/badge.svg)](https://codecov.io/gh/leapdao/leap-node) [![Docker Repository on Quay](https://quay.io/repository/leapdao/leap-node/status "Docker Repository on Quay")](https://quay.io/re

38 lines (29 loc) 820 B
const EventEmitter = require('events'); let eventsBatches = []; class ContractsEventsSubscriptionMock extends EventEmitter { constructor() { super(); this.fetchEvents = this.fetchEvents.bind(this); this.fetchCounts = 0; this.handlers = []; } subscribe(handler) { this.handlers.push(handler); } async init() { const initialEvetns = await this.fetchEvents(); return initialEvetns; } async fetchEvents() { const events = eventsBatches[this.fetchCounts] || []; this.fetchCounts += 1; this.handlers.forEach(handler => handler(events)); this.emit('newEvents', events); return events; } } /* eslint-disable */ ContractsEventsSubscriptionMock.__setEventBatches = batches => { eventsBatches = batches; }; module.exports = ContractsEventsSubscriptionMock;