refactor: introduce bindThis decorator to bind this automaticaly

This commit is contained in:
syuilo
2022-12-04 15:03:09 +09:00
parent e73581f715
commit bbb49457f9
199 changed files with 969 additions and 96 deletions

View File

@@ -1,5 +1,6 @@
import Xev from 'xev';
import { Inject, Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
const ev = new Xev();
@@ -11,18 +12,21 @@ class QueueStatsChannel extends Channel {
constructor(id: string, connection: Channel['connection']) {
super(id, connection);
this.onStats = this.onStats.bind(this);
this.onMessage = this.onMessage.bind(this);
//this.onStats = this.onStats.bind(this);
//this.onMessage = this.onMessage.bind(this);
}
@bindThis
public async init(params: any) {
ev.addListener('queueStats', this.onStats);
}
@bindThis
private onStats(stats: any) {
this.send('stats', stats);
}
@bindThis
public onMessage(type: string, body: any) {
switch (type) {
case 'requestLog':
@@ -37,6 +41,7 @@ class QueueStatsChannel extends Channel {
}
}
@bindThis
public dispose() {
ev.removeListener('queueStats', this.onStats);
}
@@ -51,6 +56,7 @@ export class QueueStatsChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): QueueStatsChannel {
return new QueueStatsChannel(
id,