feat: new UI and build process
Some checks are pending
Gitea djledda.de/arne-drums/pipeline/head Build started...

This commit is contained in:
Daniel Ledda
2021-08-29 16:21:26 +02:00
parent f2bcc81330
commit ec4587bed5
30 changed files with 769 additions and 12596 deletions

54
src/Publisher.ts Normal file
View File

@@ -0,0 +1,54 @@
import ISubscriber from "./Subscriber";
export class Publisher<T extends (string | number)> implements IPublisher<T> {
private subscribers: Map<T | "all", ISubscriber[]>;
constructor() {
this.subscribers = new Map();
this.subscribers.set("all", []);
}
addSubscriber(subscriber: ISubscriber, eventType: (T | "all") | T[]): {unbind: () => void} {
let eventTypes: (T | "all")[] = [];
if (!Array.isArray(eventType)) {
eventTypes.push(eventType);
} else {
eventTypes = eventType as (T | "all")[];
}
for (const key of eventTypes) {
this.getSubscribers(key).push(subscriber);
}
return {
unbind: () => {
for (const key of eventTypes) {
const subs = this.getSubscribers(key);
subs.splice(subs.indexOf(subscriber), 1);
}
}
};
}
private getSubscribers(key: T | "all"): ISubscriber[] {
const subscribersList = this.subscribers.get(key);
if (subscribersList === undefined) {
const newList: ISubscriber[] = [];
this.subscribers.set(key, newList);
return newList;
} else {
return subscribersList;
}
}
notifySubs(eventType: T) {
for (const sub of this.getSubscribers(eventType)) {
sub.notify(this, eventType);
}
for (const sub of this.getSubscribers("all")) {
sub.notify(this, "all");
}
}
}
export interface IPublisher<T extends string | number> {
addSubscriber(subscriber: ISubscriber, eventType: (T | "all") | T[]): {unbind: () => void};
}