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

fix!: support registering component to multiple managers #39

Merged
merged 13 commits into from
Mar 4, 2025

Conversation

Sharp-Eyes
Copy link
Member

This PR ensures that components can be registered to more than one manager without breaking.

This is done by making managers keep track of what component identifier is registered to which manager, and only making the manager available to a component instance when it is invoked.

Why?

This is a valid concern, as was brought to my attention recently, to be able to "version" components.
For example, say you have a component that used to run on legacy disnake-ext-components, and you now ported to disnake-compass; you now have the same component with two different custom id specs:
e.g. "my_button:123" for the legacy component and "MyButton|123" for the updated component.

With some clever usage of managers, you can handle both versions with the same component class:

legacy_manager = disnake_compass.get_manager("legacy")
legacy_manager.add_to_client(bot)
legacy_manager.config(sep=":")
modern_manager = disnake_compass.get_manager("modern")
modern_manager.add_to_client(bot)

@legacy_manager.register(identifier="my_button")
@modern_manager.register()
class MyButton(disnake_compass.RichButton):
    foo: int = disnake_compass.field(parser=disnake_compass.parser.IntParser(base=10))

    async def callback(self, interaction):
        ...

Breaking Changes

  • ComponentBase.factory has been replaced with the ComponentBase.get_factory class method;
  • ComponentBase.manager has been replaced with the ComponentBase.get_manager instance method;
  • Component managers are now defined on the component instance instead of the class;
  • ComponentManager.parse_message_interaction is now deprecated.

@Sharp-Eyes Sharp-Eyes merged commit 2ca8e13 into master Mar 4, 2025
7 checks passed
@Sharp-Eyes Sharp-Eyes deleted the fix/multiple-managers branch March 4, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant