Skip to content

Conversation

weaverryan
Copy link
Member

Q A
Bug fix? no
New feature? yes
Tickets Fix #612
License MIT

Hi!

My solution for #612. It seems... to work perfectly well and it's dead-simple:

const element = // find some Element that is your live controller rot

ComponentRegistry.get(element).then((component) => {
    // use the Component
    component.render()
});

// or use await
const component = await ComponentRegistry.get(element)l
component.render();

Cheers!

Copy link
Contributor

@1ed 1ed left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of this. I would like to make a few comments if you allow me.

@@ -104,6 +105,7 @@ export default class extends Controller<HTMLElement> implements LiveController {
this.component.element.addEventListener(event, callback);
});

ComponentRegistry.registerComponent(this.element, this.component);
this._dispatchEvent('live:connect');
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any use cases for listening to these events after adding the registry? Shouldn't we remove them for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wondered about that too, and you're probably correct. There might be some future need to check if a Component is connected or not, but we could easily add that to Component if needed later.

@kbond kbond changed the title [Live] Adding ComponentRegistry as an easy way to fetcha Live Component [Live] Adding ComponentRegistry as an easy way to fetch a Live Component Dec 21, 2022
@weaverryan weaverryan force-pushed the live-controller-registry branch 2 times, most recently from 04c5e2a to 4494fd9 Compare January 13, 2023 21:02
@weaverryan
Copy link
Member Author

Ok, final version of this is up. I simplified the export for userland to just the getComponent function.

@weaverryan weaverryan force-pushed the live-controller-registry branch from 4494fd9 to f4215be Compare January 18, 2023 20:27
@weaverryan weaverryan force-pushed the live-controller-registry branch from f4215be to 748b800 Compare January 19, 2023 15:30
@weaverryan weaverryan merged commit 0d14638 into symfony:2.x Jan 19, 2023
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.

[LiveComponent] Issues with custom Stimulus controller
2 participants