mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 03:00:56 +02:00
prettify, sorry for the big ass commit
This commit is contained in:
+31
-32
@@ -6,45 +6,44 @@ import { IMap } from "../types";
|
||||
type cbFn = (...args: any[]) => any;
|
||||
|
||||
export interface ISubscriber {
|
||||
/**
|
||||
* Callback function that will be run when an event is emitted
|
||||
*/
|
||||
cb: cbFn;
|
||||
/**
|
||||
* Callback function that will be run when an event is emitted
|
||||
*/
|
||||
cb: cbFn;
|
||||
|
||||
/**
|
||||
* Name/identifier for this subscriber
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Name/identifier for this subscriber
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class EventEmitter {
|
||||
/**
|
||||
* Map of Subscriber name -> Callback function
|
||||
*/
|
||||
subscribers: IMap<cbFn> = {};
|
||||
/**
|
||||
* Map of Subscriber name -> Callback function
|
||||
*/
|
||||
subscribers: IMap<cbFn> = {};
|
||||
|
||||
constructor(subs?: ISubscriber[]) {
|
||||
if (Array.isArray(subs)) {
|
||||
for (const s of subs) {
|
||||
this.addSubscriber(s);
|
||||
}
|
||||
}
|
||||
constructor(subs?: ISubscriber[]) {
|
||||
if (Array.isArray(subs)) {
|
||||
for (const s of subs) {
|
||||
this.addSubscriber(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addSubscriber(s: ISubscriber): void {
|
||||
this.subscribers[s.id] = s.cb;
|
||||
}
|
||||
|
||||
emitEvent(...args: any[]): void {
|
||||
for (const s in this.subscribers) {
|
||||
const sub = this.subscribers[s];
|
||||
|
||||
sub(args);
|
||||
}
|
||||
}
|
||||
|
||||
removeSubscriber(id: string): void {
|
||||
delete this.subscribers[id];
|
||||
addSubscriber(s: ISubscriber): void {
|
||||
this.subscribers[s.id] = s.cb;
|
||||
}
|
||||
|
||||
emitEvent(...args: any[]): void {
|
||||
for (const s in this.subscribers) {
|
||||
const sub = this.subscribers[s];
|
||||
|
||||
sub(args);
|
||||
}
|
||||
}
|
||||
|
||||
removeSubscriber(id: string): void {
|
||||
delete this.subscribers[id];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user