Skip to content

feat: Add Messenger parent parameter #6142

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

Draft
wants to merge 3 commits into
base: add-messenger-delegation
Choose a base branch
from

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jul 17, 2025

Explanation

Add the parent constructor parameter to the Messenger class for automatic delegation of all capabilities under that messenger's namespace. This significantly reduces boilerplate, making the messenger easier to use in a similar manner to how the old RestrictedMessenger class wored.

See this ADR PR for details: MetaMask/decisions#53

References

Depends upon #6132
Relates to #5626

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

The methods `delegate` and `revoke` have been added to the Messenger
class. These methods replace the need for the `RestrictedMessenger`.
The `getRestricted` method, and the `RestrictedMessenger` class, have
been removed as obsolete.

See this ADR PR for details: MetaMask/decisions#53
@Gudahtt Gudahtt force-pushed the add-messenger-parent-param branch from 73f9dd4 to c07ba89 Compare July 17, 2025 16:15
@Gudahtt Gudahtt force-pushed the add-messenger-parent-param branch from c07ba89 to 4ff719e Compare July 17, 2025 16:30
Add the `parent` constructor parameter to the `Messenger` class for
automatic delegation of all capabilities under that messenger's
namespace. This significantly reduces boilerplate, making the messenger
easier to use in a similar manner to how the old `RestrictedMessenger`
class wored.

See this ADR PR for details: MetaMask/decisions#53
@Gudahtt Gudahtt force-pushed the add-messenger-parent-param branch from 4ff719e to f3e18ba Compare July 17, 2025 16:31
@Gudahtt Gudahtt changed the title feat: Add Messenger parant parameter feat: Add Messenger parent parameter Jul 17, 2025
@Gudahtt Gudahtt force-pushed the add-messenger-delegation branch from 2dd241a to 6729773 Compare July 23, 2025 20:11
Comment on lines +141 to +145
readonly #parent?: Messenger<
string,
Action | ActionConstraint,
Event | EventConstraint
>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it true that 1) all of the actions and events in this messenger are eligible for delegation, and because of this, 2) all of the actions and events that the parent knows about must be known to this messenger too? If so, can we say this?

Suggested change
readonly #parent?: Messenger<
string,
Action | ActionConstraint,
Event | EventConstraint
>;
readonly #parent?: DelegatedMessenger<Action, Event>;

Comment on lines +203 to +207
parent?: Messenger<
string,
Action | ActionConstraint,
Event | EventConstraint
>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar as above, can we say this?

Suggested change
parent?: Messenger<
string,
Action | ActionConstraint,
Event | EventConstraint
>;
parent?: DelegatedMessenger<Action, Event>;

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.

2 participants