Skip to content
Snippets Groups Projects
Verified Commit c1df63fe authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Hide EventEmitter internals from the end-user

parent 6194a77a
No related branches found
No related tags found
1 merge request!23Dependencies-related work
...@@ -40,31 +40,6 @@ export const DEFAULT_WORKERBEE_OPTIONS = { ...@@ -40,31 +40,6 @@ export const DEFAULT_WORKERBEE_OPTIONS = {
export const DEFAULT_BLOCK_INTERVAL_TIMEOUT = 1500; export const DEFAULT_BLOCK_INTERVAL_TIMEOUT = 1500;
interface IWorkerBeeEvents {
"stop": () => void | Promise<void>;
"start": () => void | Promise<void>;
"block": (blockData: IBlockData) => void | Promise<void>;
"transaction": (transactionData: ITransactionData) => void | Promise<void>;
"error": (error: WorkerBeeError) => void | Promise<void>;
}
/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
export declare interface WorkerBee {
on<U extends keyof IWorkerBeeEvents>(
event: U, listener: IWorkerBeeEvents[U]
): this;
once<U extends keyof IWorkerBeeEvents>(
event: U, listener: IWorkerBeeEvents[U]
): this;
off<U extends keyof IWorkerBeeEvents>(
event: U, listener: IWorkerBeeEvents[U]
): this;
}
/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
export class WorkerBee extends EventEmitter implements IWorkerBee { export class WorkerBee extends EventEmitter implements IWorkerBee {
public running: boolean = false; public running: boolean = false;
......
import type EventEmitter from "events";
import type { IBeekeeperUnlockedWallet } from "@hiveio/beekeeper"; import type { IBeekeeperUnlockedWallet } from "@hiveio/beekeeper";
import type { ApiAccount, ApiBlock, ApiTransaction, IHiveChainInterface, ITransaction, operation } from "@hiveio/wax"; import type { ApiAccount, ApiBlock, ApiTransaction, IHiveChainInterface, ITransaction, operation } from "@hiveio/wax";
import type { Subscribable } from "rxjs"; import type { Subscribable } from "rxjs";
import type { IStartConfiguration } from "./bot"; import type { IStartConfiguration } from "./bot";
import type { WorkerBeeError } from "./errors";
export interface IBlockData { export interface IBlockData {
number: number; number: number;
...@@ -64,7 +64,7 @@ export interface IQueenBee { ...@@ -64,7 +64,7 @@ export interface IQueenBee {
export interface IBroadcastOptions { export interface IBroadcastOptions {
/** /**
* Can be either absolute time that will be passed to the {@link Date} constructor * Can be either absolute time that will be passed to the Date constructor
* or relative time, like: "+10s", "+2m", "+1h" * or relative time, like: "+10s", "+2m", "+1h"
* *
* @type {string | number | Date} * @type {string | number | Date}
...@@ -73,7 +73,15 @@ export interface IBroadcastOptions { ...@@ -73,7 +73,15 @@ export interface IBroadcastOptions {
throwAfter?: string | number | Date; throwAfter?: string | number | Date;
} }
export interface IWorkerBee extends EventEmitter { export interface IWorkerBeeEvents {
"stop": () => void | Promise<void>;
"start": () => void | Promise<void>;
"block": (blockData: IBlockData) => void | Promise<void>;
"transaction": (transactionData: ITransactionData) => void | Promise<void>;
"error": (error: WorkerBeeError) => void | Promise<void>;
}
export interface IWorkerBee {
readonly running: boolean; readonly running: boolean;
readonly configuration: Readonly<IStartConfiguration>; readonly configuration: Readonly<IStartConfiguration>;
...@@ -123,41 +131,17 @@ export interface IWorkerBee extends EventEmitter { ...@@ -123,41 +131,17 @@ export interface IWorkerBee extends EventEmitter {
*/ */
[Symbol.asyncIterator](): AsyncIterator<IBlockData>; [Symbol.asyncIterator](): AsyncIterator<IBlockData>;
/** on<U extends keyof IWorkerBeeEvents>(
* Triggers on any bot start event: U, listener: IWorkerBeeEvents[U]
* ): this;
* @param event event name
* @param handler handler to be called before automation start once<U extends keyof IWorkerBeeEvents>(
*/ event: U, listener: IWorkerBeeEvents[U]
on(event: "start", handler: () => void): this; ): this;
/**
* Triggers on any bot stop off<U extends keyof IWorkerBeeEvents>(
* event: U, listener: IWorkerBeeEvents[U]
* @param event event name ): this;
* @param handler handler to be called after complete stop of the automation
*/
on(event: "stop", handler: () => void): this;
/**
* Triggers on any bot-related error
*
* @param event event name
* @param handler handler to be called on error event
*/
on(event: "error", handler: (error: Error) => void): this;
/**
* Triggers on new block detected
*
* @param event event name
* @param handler handler to be called on new block event
*/
on(event: "block", handler: (data: IBlockData) => void): this;
/**
* Triggers on new transaction detected
*
* @param event event name
* @param handler handler to be called on new block event
*/
on(event: "transaction", handler: (data: ITransactionData) => void): this;
} }
export interface IWorkerBeeConstructor { export interface IWorkerBeeConstructor {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment