Skip to content

Commit

Permalink
Add autobinding to subscriptions and address
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jul 15, 2022
1 parent 25c4f7b commit 6786ae4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "everscale-inpage-provider",
"version": "0.3.27",
"version": "0.3.28",
"description": "Web3-like interface to the Everscale blockchain",
"repository": "https://github.com/broxus/everscale-inpage-provider",
"main": "dist/index.js",
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class ProviderRpcClient {
return this;
}

async subscribe(): Promise<void> {
subscribe = async (): Promise<void> => {
if (this._subscribed) {
return;
}
Expand All @@ -375,9 +375,9 @@ export class ProviderRpcClient {
for (const handler of this._listeners['subscribed']) {
handler();
}
}
};

async unsubscribe(): Promise<void> {
unsubscribe = async (): Promise<void> => {
if (!this._subscribed) {
return;
}
Expand All @@ -387,7 +387,7 @@ export class ProviderRpcClient {
for (const handler of this._listeners['unsubscribed']) {
handler();
}
}
};

notify(data: ProviderEventData<T>) {
for (const handler of this._listeners['data']) {
Expand Down Expand Up @@ -923,12 +923,12 @@ export interface Subscription<T extends ProviderEvent> {
/**
* Can be used to re-subscribe with the same parameters.
*/
subscribe(): Promise<void>;
subscribe: () => Promise<void>;

/**
* Unsubscribes the subscription.
*/
unsubscribe(): Promise<void>;
unsubscribe: () => Promise<void>;
}

type SubscriptionEvent = 'data' | 'subscribed' | 'unsubscribed';
Expand Down
4 changes: 3 additions & 1 deletion src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export class Subscriber {
return this._addSubscription('contractStateChanged', address, false);
}

public async unsubscribe(): Promise<void> {
public unsubscribe = async (): Promise<void> => this._unsubscribe();

private async _unsubscribe(): Promise<void> {
const subscriptions = Object.assign({}, this.subscriptions);
for (const address of Object.keys(this.subscriptions)) {
delete this.subscriptions[address];
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class Address {
return this._address;
}

public equals(other: Address | string): boolean {
public equals = (other: Address | string): boolean => this._equals(other);

private _equals(other: Address | string): boolean {
if (other instanceof Address) {
return this._address == other._address;
} else {
Expand Down

0 comments on commit 6786ae4

Please sign in to comment.