-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
[composable-controller] Subscribe to stateChange
events of V1 controllers with messenger, type fixes
#3964
Conversation
cac2559
to
0c830ba
Compare
0c830ba
to
599fd44
Compare
bdc167c
to
0882483
Compare
stateChange
events of V1 controllers with messenger, type fixes
@MajorLift in case of BaseControllerV1 without messagingSystem shouldn't we throw an error ? Or in this case I guess we would want only to save the initial state within the ComposableController ? |
@cryptodev-2s Hey thanks for taking a look at this! A This PR enables composable-controller to handle V1 controllers like |
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!
6ef730e
to
0fa97c3
Compare
0ab242a
to
0fa97c3
Compare
… `stateChange` event
…trollerInstance`, as these are unsuited for general use
…sistency with `isBaseController` type guard
…rd<string, unknown>`
0fa97c3
to
7d46b06
Compare
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 mostly good! Just had one question.
* | ||
* The `BaseController` class itself can't be used directly as a type representing all of its subclasses, | ||
* because the generic parameters it expects require knowing the exact shape of the controller's state and messenger. | ||
* Note that this type is not the greatest subtype or narrowest supertype of all `BaseController` instances. |
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.
👍🏻
if ( | ||
(isBaseControllerV1(controller) && 'messagingSystem' in controller) || | ||
isBaseController(controller) | ||
) { | ||
this.messagingSystem.subscribe( |
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.
If a BaseControllerV1 controller has a messagingSystem
property, could the state of this controller could be updated twice per update? If so, do we still need an else if
?
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.
Great point! Fixed here: 811a94a
…controllers with messaging system Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
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!
Explanation
stateChange
event.@metamask/utils
as a dependency.BaseControllerV{1,2}Instance
,ControllerInstance
, as these are incomplete and unsuited for general usage.isBaseController{,V1}
are not removed.BaseControllerV2Instance
asBaseControllerInstance
for consistency withisBaseController
.References
stateChange
events of V1 controllers with messenger #3966Changelog
@metamask/composable-controller
Checklist