mirror of
https://github.com/BlowaterNostr/blowater.git
synced 2024-10-18 15:43:20 +00:00
e86101ae7f
* remove nip-07 extension sign-in temporarily * bring kind-1 back! * separated relay views
24 lines
613 B
TypeScript
24 lines
613 B
TypeScript
import { chan, Channel, multi } from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
|
|
|
|
export class EventBus<T> implements EventEmitter<T>, EventSubscriber<T> {
|
|
private readonly c = chan<T>();
|
|
private readonly caster = multi<T>(this.c);
|
|
|
|
emit = async (event: T) => {
|
|
await this.c.put(event);
|
|
};
|
|
|
|
onChange() {
|
|
return this.caster.copy();
|
|
}
|
|
}
|
|
|
|
export type EventEmitter<T> = {
|
|
emit: (event: T) => void;
|
|
};
|
|
export type emitFunc<T extends { type: string }> = (event: T) => Promise<void>;
|
|
|
|
export type EventSubscriber<T> = {
|
|
onChange(): Channel<T>;
|
|
};
|