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

How to get component instance by a component name? #2998

Closed
kachurunus opened this issue Mar 25, 2024 · 1 comment
Closed

How to get component instance by a component name? #2998

kachurunus opened this issue Mar 25, 2024 · 1 comment

Comments

@kachurunus
Copy link
Contributor

I've updated from 6.1.4 to 9.x and lost the ability to get a component instance by its name. I need this because I register all my components globally and always use them by name. I also have what you might call a "proxy" component in another framework (actually, it's riot3), and I call this proxy component like this:

<proxy component="my-fancy-riot-component" some-prop="123">Yes, I will need this slot too.</proxy>

So, inside this proxy component, I need to get the component implementation to mount it:

const component = riot.__.globals.COMPONENTS_IMPLEMENTATION_MAP.get(componentName);
const slots = this.showSlot ? [{
    id: 'default',
    html: '<mark class="default"></mark>'
}] : [];

this.component = component({ props, slots }).mount(this.root, this);

Before, I got it through riot.__.globals, and now I've lost this ability. I can't just use the riot.mount method because it doesn't support slots (by the way, mountComponent(element, initialProps, componentName, slots) in the riot source code is private and is never called with the 4th argument).

I have two ideas:

Add a get method to the API to get the component implementation by name.
Export the core mountComponent method.

@GianlucaGuarini
Copy link
Member

Thank you @kachurunus for your PR. Your patch was included in riot@9.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants