UNPKG

event-local

Version:

Event client

49 lines (42 loc) 1.8 kB
global.EVENT_CHANNEL = []; global.MESSAGE_CHANNEL = []; global.API_CHANNEL = []; global.SET_BROKER = []; /** * Декоратор. Подписка на доменные события * @param id Идентификатор долговременной подписки */ export function EventSubscriber(id: string): Function { return function(constructor: Function) { // подписывается на событие // console.log(`[*] Channel ${id} is open`) }; } export function EventHeandlerMethod(id: string): Function { return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { // подписывается на событие global.EVENT_CHANNEL.push({event: id, callback: target[propertyKey]}); }; } /** * Декоратор. Подписка на сообщения из чат бота * @param id Идентификатор долговременной подписки */ export function MessageSubscriber(id: string): Function { return function(constructor: Function) { // подписывается на событие // console.log(`[*] Channel ${id} is open`) }; } export function MessageHeandlerMethod(id: RegExp): Function { return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { // подписывается на события global.MESSAGE_CHANNEL.push({event: id, callback: target[propertyKey]}); }; } export function API(method: 'get' | 'post' | 'delete' | 'push' ,url: string): Function { return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { // подписывается на события global.API_CHANNEL.push({method: method, url: url, callback: target[propertyKey]}); }; }