refactor event handling to consume base class for lifecycling
This commit is contained in:
12
src/infrastructure/Events/EventSubscriptionCollection.ts
Normal file
12
src/infrastructure/Events/EventSubscriptionCollection.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { IEventSubscription } from './IEventSource';
|
||||
|
||||
export class EventSubscriptionCollection {
|
||||
private readonly subscriptions = new Array<IEventSubscription>();
|
||||
public register(...subscriptions: IEventSubscription[]) {
|
||||
this.subscriptions.push(...subscriptions);
|
||||
}
|
||||
public unsubscribeAll() {
|
||||
this.subscriptions.forEach((listener) => listener.unsubscribe());
|
||||
this.subscriptions.splice(0, this.subscriptions.length);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user