-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
The notification center is actually not typed, so there is no compile time verification about typings with events.
To type the notification center I propose to add typings informations to the event: the event would not be a "string" anymore pour an object holding type informations.
export interface Notification<ObjectType extends Object, UserInfoType extends {} | undefined> {
name: Event<ObjectType, UserInfoType>;
object: ObjectType;
info: UserInfoType
}
export class Event<ObjectType, UserInfoType> {
constructor(public name: string) { }
Notification: Notification<ObjectType, UserInfoType>;
toString() { return `<Event:${this.name}>`; }
}
let notificationCenter = new NotificationCenter();
let myEvent = new Event<MyEmitClass, { a1: string }>("myEvent");
class MyObsClass {
register() {
notificationCenter.addObserver(this, "onMyEvent", myEvent);
}
onMyEvent(notification: typeof myEvent.Notification) { }
}