-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
Added options to PollingController to help handle cases where the Controller need more than just networkClientId #1776
Conversation
…troller need more than just networkClientId
…t to handle different options and stopping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. A few small nits. Still would like approval from @mcmire before we merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main question is around the name we want to choose for the keys in this.#networkClientIdTokensMap
(and other places), however, I'd also like to see the options
receive a more accurate type (or at the very least, a consistent type instead of sometimes any
and sometimes object
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still wondering if we could add another test here (per this comment) but otherwise LGTM. Maybe lets do Elliot one last pass before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there's still a bit of confusion on what things hold what things and what they should be called. I have a couple more comments on that.
@@ -20,10 +34,9 @@ function PollingControllerMixin<TBase extends Constructor>(Base: TBase) { | |||
* | |||
*/ | |||
abstract class PollingControllerBase extends Base { | |||
readonly #networkClientIdTokensMap: Map<NetworkClientId, Set<string>> = | |||
new Map(); | |||
readonly #pollingGroupIds: Map<PollingGroupId, Set<string>> = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pollingGroupIds
sounds like this variable holds an array of ids. What do you think about:
readonly #pollingGroupIds: Map<PollingGroupId, Set<string>> = new Map(); | |
readonly #pollTokenGroups: Map<PollingGroupId, Set<string>> = new Map(); |
On the other hand, it seems like when we use this variable we really care about the poll tokens. Also, intervalIds
and callbacks
seem to be named after the values that they hold, and so maybe it makes sense for this variable to follow the same pattern:
readonly #pollingGroupIds: Map<PollingGroupId, Set<string>> = new Map(); | |
readonly #pollTokens: Map<PollingGroupId, Set<string>> = new Map(); |
|
||
const key = getKey(networkClientId, options); | ||
|
||
const pollingGroupId = this.#pollingGroupIds.get(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? I thought each value in #pollingGroupIds
is set of poll tokens. It seems that key
here is really the polling group ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah currently the type you have returned for getKey
is PollingGroupId
, so presumably you'd use the pollingGroupId
to get a pollingGroup
or pollingTokenGroup
or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea really it should be pollingTokenSet
, and #pollingGroupIds
should be #pollingTokenSets
or #pollingTokensByPollingGroupId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably pollingTokenSets
though since it would be kindof weird for pollingTokenSet
to be a subset of pollingTokens
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Sorry for all of the back and forth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
options: Json, | ||
): PollingGroupId => `${networkClientId}:${stringify(options)}`; | ||
|
||
type PollingGroupId = `${NetworkClientId}:${string}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] last thing is maybe we should align with the pollingTokenSet
verbiage -> PollingTokenSetId
?
…troller need more than just networkClientId (#1776) ## Explanation Adds `options` parameter passed around to allow a unique key to be derived per networkClientId + option combination. This handles cases where a Controller need more than just networkClientId to poll on, like an `address` for example. Fixes MetaMask/MetaMask-planning#1406 ## Changelog ### `@metamask/polling-controller` - **ADDED**: options to PollingController Mixin to help handle cases where a Controller need more than just networkClientId --------- Co-authored-by: Alex Donesky <[email protected]>
…troller need more than just networkClientId (#1776) ## Explanation Adds `options` parameter passed around to allow a unique key to be derived per networkClientId + option combination. This handles cases where a Controller need more than just networkClientId to poll on, like an `address` for example. Fixes MetaMask/MetaMask-planning#1406 ## Changelog ### `@metamask/polling-controller` - **ADDED**: options to PollingController Mixin to help handle cases where a Controller need more than just networkClientId --------- Co-authored-by: Alex Donesky <[email protected]>
…troller need more than just networkClientId (#1776) ## Explanation Adds `options` parameter passed around to allow a unique key to be derived per networkClientId + option combination. This handles cases where a Controller need more than just networkClientId to poll on, like an `address` for example. Fixes MetaMask/MetaMask-planning#1406 ## Changelog ### `@metamask/polling-controller` - **ADDED**: options to PollingController Mixin to help handle cases where a Controller need more than just networkClientId --------- Co-authored-by: Alex Donesky <[email protected]>
Explanation
Adds
options
parameter passed around to allow a unique key to be derived per networkClientId + option combination. This handles cases where a Controller need more than just networkClientId to poll on, like anaddress
for example.References
Fixes https://github.com/MetaMask/MetaMask-planning/issues/1406
Changelog
@metamask/polling-controller