npm.io
0.1.4 • Published 6 years ago

andshil-ts-notifications

Licence
MIT
Version
0.1.4
Deps
0
Size
7 kB
Vulns
0
Weekly
0

andshil-ts-notifications

Typescript realization concept of events

sample:

class NotificationMap extends Notify.NotificationMap { // concreat NotificationMap class

}

class Recipient implements Notify.IRecipient {
    shouldReceiveNotifications: boolean = true;
    notificationMap: Notify.NotificationMap;

    constructor(notificationMap: Notify.NotificationMap) {
        this.notificationMap = notificationMap;
    }
    handleNotification(notification: Notify.Notification): void {
        console.log(`incomming ${notification.name}`);
    }
    getInterests(): string[] {
        return [
            "TEST_EVENT",
        ]
    }
    sendNotification(type: string, body?: any): void {
        this.notificationMap.notify(new Notify.Notification(type, body));
    }
    
}

const notificationMap: NotificationMap = new NotificationMap(); // create notification map
const recipient: IRecipient = new Recipient(notificationMap); // create recipient
notificationMap.register(recipient); // register recipient
recipient.sendNotification("TEST_EVENT"); // send notification to map, that we will get as interest event at recipients
recipient.sendNotification("NOT_INTEREST_EVENT"); // send event with not listen for test

Keywords