Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed PollingController to be a mixin so it can be used with both V1 and V2 controllers #1736

Merged
merged 9 commits into from
Sep 28, 2023

Conversation

shanejonas
Copy link
Contributor

@shanejonas shanejonas commented Sep 27, 2023

Explanation

  • Currently the PollingController extends from BaseControllerV2 but we need to use it for both V1 and V2 controllers.
  • This PR uses typescript mixins to achieve a faux-multiple inheritance which TypeScript has support for. The pattern
    allows you to create a class which is a merge of many classes. I've added a V1 and a V2 version of the PollingController that can be used almost the same way as the original PollingController.

@shanejonas shanejonas requested a review from a team as a code owner September 27, 2023 15:59
@shanejonas shanejonas changed the title Fixed PollingController to be a mixin so it can be used with both V1 and V2 controllers Changed PollingController to be a mixin so it can be used with both V1 and V2 controllers Sep 27, 2023
}
setIntervalLength(length: number) {
this.#intervalLength = length;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does intervalLength need to be private if we're just exposing it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make it protected so that the extending class could decide to expose it or not. I doubt we need this to be configurable at runtime very often, if ever.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't make it protected with the mixin pattern, i get this error:

Property 'intervalLength' of exported class expression may not be private or protected.ts(4094)

image

Copy link
Contributor Author

@shanejonas shanejonas Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a way to do this (make it protected), just not if I have an abstract class where the class has to be named.

see: microsoft/TypeScript#30355

} catch (error) {
console.error(error);

onPollingComplete(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit]

Suggested change
onPollingComplete(
setOnPollingComplete(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit more conventional as-is IMO. Event listeners are usually on____. Or add___Listener

messenger,
metadata,
});
#intervalLength = 1000;
Copy link
Contributor

@adonesky1 adonesky1 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Wondering if we ought remove a default and throw if never set?

adonesky1
adonesky1 previously approved these changes Sep 27, 2023
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I can re-review after some of these suggestions are resolved

shanejonas and others added 3 commits September 28, 2023 06:23
@adonesky1 adonesky1 merged commit 897ba05 into main Sep 28, 2023
107 checks passed
@adonesky1 adonesky1 deleted the polling-controller-mixin branch September 28, 2023 14:52
adonesky1 added a commit that referenced this pull request Sep 29, 2023
Integrates recently introduced [`PollingController`
mixin](#1736) with
`GasFeeController`. Leaves old polling pattern in pace for now so as to
not force a ton of breaking changes for mobile, but with intention to
activate new pattern in both clients ASAP.

Addresses: MetaMask/MetaMask-planning#1314
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…1 and V2 controllers (#1736)

## Explanation
- Currently the PollingController extends from BaseControllerV2 but we
need to use it for both V1 and V2 controllers.
- This PR uses typescript
[mixins](https://www.typescriptlang.org/docs/handbook/mixins.html) to
achieve a faux-multiple inheritance which TypeScript has support for.
The pattern
allows you to create a class which is a merge of many classes. I've
added a V1 and a V2 version of the PollingController that can be used
almost the same way as the original `PollingController`.

---------

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
Integrates recently introduced [`PollingController`
mixin](#1736) with
`GasFeeController`. Leaves old polling pattern in pace for now so as to
not force a ton of breaking changes for mobile, but with intention to
activate new pattern in both clients ASAP.

Addresses: MetaMask/MetaMask-planning#1314
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…1 and V2 controllers (#1736)

## Explanation
- Currently the PollingController extends from BaseControllerV2 but we
need to use it for both V1 and V2 controllers.
- This PR uses typescript
[mixins](https://www.typescriptlang.org/docs/handbook/mixins.html) to
achieve a faux-multiple inheritance which TypeScript has support for.
The pattern
allows you to create a class which is a merge of many classes. I've
added a V1 and a V2 version of the PollingController that can be used
almost the same way as the original `PollingController`.

---------

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
Integrates recently introduced [`PollingController`
mixin](#1736) with
`GasFeeController`. Leaves old polling pattern in pace for now so as to
not force a ton of breaking changes for mobile, but with intention to
activate new pattern in both clients ASAP.

Addresses: MetaMask/MetaMask-planning#1314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants