Skip to content

Commit

Permalink
fix: 部分class添加bind this
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Oct 9, 2024
1 parent b876e24 commit e756436
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/timestamp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class Environment extends EnvironmentConfig {
DATABASE: KVNamespace = null as any;
API_GUARD: APIGuard | null = null;

constructor() {
super();
this.merge = this.merge.bind(this);
}

merge(source: any) {
// 全局对象
this.DATABASE = source.DATABASE;
Expand Down
2 changes: 2 additions & 0 deletions src/telegram/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class APIClientBase {
while (this.baseURL.endsWith('/')) {
this.baseURL = this.baseURL.slice(0, -1);
}
this.request = this.request.bind(this);
this.requestJSON = this.requestJSON.bind(this);
}

private uri(method: Telegram.BotMethod): string {
Expand Down
3 changes: 3 additions & 0 deletions src/telegram/utils/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class MessageSender {
constructor(token: string, context: MessageContext) {
this.api = createTelegramBotAPI(token);
this.context = context;
this.sendRichText = this.sendRichText.bind(this);
this.sendPlainText = this.sendPlainText.bind(this);
this.sendPhoto = this.sendPhoto.bind(this);
}

static from(token: string, message: Telegram.Message): MessageSender {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class Cache<T> {
this.maxItems = 10;
this.maxAge = 1000 * 60 * 60;
this.cache = {};
this.set = this.set.bind(this);
this.get = this.get.bind(this);
}

set(key: string, value: T) {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ export class Router {
this.routes = routes;
this.base = base;
Object.assign(this, other);
this.fetch = this.fetch.bind(this);
this.route = this.route.bind(this);
this.get = this.get.bind(this);
this.post = this.post.bind(this);
this.put = this.put.bind(this);
this.delete = this.delete.bind(this);
this.patch = this.patch.bind(this);
this.head = this.head.bind(this);
this.options = this.options.bind(this);
this.all = this.all.bind(this);
}

private parseQueryParams(searchParams: URLSearchParams): QueryParams {
Expand Down

0 comments on commit e756436

Please sign in to comment.