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

[composable-controller] Narrow class and messenger types by parameterizing over child controllers list #3952

Merged
merged 26 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
83b976b
Establish API for generic controller class
MajorLift Mar 3, 2024
24de570
Fix types for `metadata`, `state` class fields
MajorLift Mar 3, 2024
24247ea
Implement `ComposedControllerState` using mapped type and key remapping
MajorLift Mar 3, 2024
f3dfd64
Derive `ComposedControllerStateChangeEvent` using `ControllerStateCha…
MajorLift Mar 3, 2024
340678e
Derive `ChildControllersStateChangeEvents` using distributive propert…
MajorLift Mar 3, 2024
ec26f6f
Update changelog
MajorLift Mar 3, 2024
5c7771b
Add const assertions to `name` class field of all V1 controllers
MajorLift Mar 11, 2024
2457e2a
test: Add new mock controller to test composing two V2 controllers
MajorLift Mar 11, 2024
a99a6d3
Clarify usage of "widest subtype" in jsdoc
MajorLift Apr 17, 2024
33d93e0
Define narrowest supertype of `RestrictedControllerMessenger`
MajorLift Apr 17, 2024
fc91ff8
Define a type for state-change events for both v1 and v2 controllers
MajorLift Apr 17, 2024
4b8f6c7
Rename narrowest supertype for composable controller state to use "Co…
MajorLift Apr 17, 2024
186d637
Remove references to `ComposedControllerMessenger` and `ComposedContr…
MajorLift Apr 25, 2024
46228aa
Define state constraint types
MajorLift Apr 25, 2024
5248fcf
Define `stateChange` events and controller-messenger types
MajorLift Apr 25, 2024
cd9294b
Define type for child controllers
MajorLift Apr 25, 2024
7f2b0a0
Remove duplicate from merge conflict
MajorLift Apr 25, 2024
719a365
Add package-level exports
MajorLift Apr 25, 2024
58ba8bc
Adapt tests
MajorLift Apr 25, 2024
aa05cf1
Fix changelog by removing unreleased changes
MajorLift Apr 25, 2024
e36ab32
Add `as const` assertions to overrides of `name` property in v1 contr…
MajorLift Apr 25, 2024
25f2f0b
Descriptive generic param name
MajorLift May 29, 2024
365aa02
Update changelog
MajorLift May 29, 2024
3f0d0e2
Merge branch 'main' into 240220-composable-controller-narrow-typing
MajorLift May 29, 2024
fdbfb3c
Merge branch 'main' into 240220-composable-controller-narrow-typing
MajorLift May 30, 2024
e6b67a0
Merge branch 'main' into 240220-composable-controller-narrow-typing
MajorLift May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class AddressBookController extends BaseControllerV1<
/**
* Name of this controller used during composition
*/
override name = 'AddressBookController';
override name = 'AddressBookController' as const;

/**
* Creates an AddressBookController instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class AccountTrackerController extends StaticIntervalPollingControllerV1<
/**
* Name of this controller used during composition
*/
override name = 'AccountTrackerController';
override name = 'AccountTrackerController' as const;

private readonly getIdentities: () => PreferencesState['identities'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class AssetsContractController extends BaseControllerV1<
/**
* Name of this controller used during composition
*/
override name = 'AssetsContractController';
override name = 'AssetsContractController' as const;

private readonly getNetworkClientById: NetworkController['getNetworkClientById'];

Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export class NftController extends BaseControllerV1<NftConfig, NftState> {
/**
* Name of this controller used during composition
*/
override name = 'NftController';
override name = 'NftController' as const;

private readonly getERC721AssetName: AssetsContractController['getERC721AssetName'];

Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class TokenRatesController extends StaticIntervalPollingControllerV1<
/**
* Name of this controller used during composition
*/
override name = 'TokenRatesController';
override name = 'TokenRatesController' as const;

private readonly getNetworkClientById: NetworkController['getNetworkClientById'];

Expand Down
12 changes: 12 additions & 0 deletions packages/composable-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Adds and exports new types: ([#3952](https://github.com/MetaMask/core/pull/3952))
- `RestrictedControllerMessengerConstraint`, which is the narrowest supertype of all controller-messenger instances.
- `LegacyControllerStateConstraint`, a universal supertype for the controller state object, encompassing both BaseControllerV1 and BaseControllerV2 state.
- `ComposableControllerStateConstraint`, the narrowest supertype for the composable controller state object.

### Changed

- **BREAKING:** The `ComposableController` class is now a generic class that expects one generic argument `ComposableControllerState` ([#3952](https://github.com/MetaMask/core/pull/3952)).
- **BREAKING:** For the `ComposableController` class to be typed correctly, any of its child controllers that extend `BaseControllerV1` must have an overridden `name` property that is defined using the `as const` assertion.

## [6.0.1]

### Fixed
Expand Down
Loading
Loading