2023-04-15 06:21:50 +00:00
|
|
|
import { Auto } from './auto';
|
2020-11-21 15:41:08 +00:00
|
|
|
|
2020-11-29 19:23:43 +00:00
|
|
|
/**
|
|
|
|
* Listen for an event targeted towards this plugin.
|
|
|
|
* @param event Event name
|
|
|
|
*/
|
2023-04-15 06:21:50 +00:00
|
|
|
export function EventListener(event: string) {
|
2020-11-21 15:41:08 +00:00
|
|
|
return (
|
|
|
|
target: any,
|
|
|
|
propertyKey: string,
|
|
|
|
descriptor: PropertyDescriptor,
|
|
|
|
) => {
|
|
|
|
const originalMethod = descriptor.value;
|
|
|
|
descriptor.value = function(...args: any[]): void {
|
|
|
|
// This ugly hack because TS thinks 'this'
|
|
|
|
// is still referring to 'PropertyDescriptor'
|
|
|
|
const self = this as any;
|
|
|
|
self.stream.on(self.name, event, (...data: any[]) =>
|
|
|
|
originalMethod.apply(self, data),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
// Set the function to be autoexecuted when the plugin is initialized.
|
2023-04-15 06:21:50 +00:00
|
|
|
Auto()(target, propertyKey, descriptor);
|
2020-11-21 15:41:08 +00:00
|
|
|
return descriptor;
|
|
|
|
};
|
|
|
|
}
|