Skip to content

Commit

Permalink
Upgrade ComposableController to extend BaseControllerV2 (#3590)
Browse files Browse the repository at this point in the history
## Explanation

As part of the upcoming core wallet library initiative, we plan to
migrate all controllers to `BaseControllerV2`. This commit upgrades
`ComposableController`.

## References

- Closes #2082
- See #1509

## Changelog

### `@metamask/composable-controller`

## Added

- Add types `ComposableControllerState`,
`ComposableControllerStateChangeEvent`, `ComposableControllerEvents`,
`ComposableControllerMessenger`.

## Changed

- **BREAKING:** `ComposableController` is upgraded to extend
`BaseControllerV2`.
- The constructor now expects an options object with required properties
`controllers` and `messenger` as its only argument.
- `ComposableController` no longer has a `subscribe` method. Instead,
listeners for `ComposableController` events must be registered to the
controller messenger that generated the restricted messenger assigned to
the instance's `messagingSystem` class field.
- Any getters for `ComposableController` state that access the internal
class field directly should be refactored to instead use listeners that
are subscribed to `ComposableControllerStateChangeEvent`.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Ellilot Winkler <elliot.winkler@gmail.com>
  • Loading branch information
MajorLift and mcmire committed Dec 11, 2023
1 parent dd0e83e commit 9ea6b88
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 190 deletions.
7 changes: 0 additions & 7 deletions packages/base-controller/src/BaseControllerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ export class BaseController<

public readonly metadata: StateMetadata<ControllerState>;

/**
* The existence of the `subscribe` property is how the ComposableController detects whether a
* controller extends the old BaseController or the new one. We set it to `undefined` here to
* ensure the ComposableController never mistakes them for an older style controller.
*/
public readonly subscribe: undefined;

/**
* Creates a BaseController instance.
*
Expand Down
8 changes: 8 additions & 0 deletions packages/composable-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add types `ComposableControllerState`, `ComposableControllerStateChangeEvent`, `ComposableControllerEvents`, `ComposableControllerMessenger` ([#3590](https://github.com/MetaMask/core/pull/3590))

### Changed
- **BREAKING:** `ComposableController` is upgraded to extend `BaseControllerV2` ([#3590](https://github.com/MetaMask/core/pull/3590))
- The constructor now expects an options object with required properties `controllers` and `messenger` as its only argument.
- `ComposableController` no longer has a `subscribe` method. Instead, listeners for `ComposableController` events must be registered to the controller messenger that generated the restricted messenger assigned to the instance's `messagingSystem` class field.
- Any getters for `ComposableController` state that access the internal class field directly should be refactored to instead use listeners that are subscribed to `ComposableControllerStateChangeEvent`.

## [4.0.0]
### Changed
Expand Down
Loading

0 comments on commit 9ea6b88

Please sign in to comment.