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

[LiveComponent] Emit events: targeting one of many with the same name #2473

Open
haivala opened this issue Dec 30, 2024 · 0 comments
Open

[LiveComponent] Emit events: targeting one of many with the same name #2473

haivala opened this issue Dec 30, 2024 · 0 comments

Comments

@haivala
Copy link

haivala commented Dec 30, 2024

I'm aware of https://symfony.com/bundles/ux-live-component/current/index.html#emitting-only-to-components-with-a-specific-name, #2422 and there is https://symfony-devs.slack.com/archives/C01FN4EQNLX/p1734560066862169 and from that https://www.bradirby.com/difference-between-event-and-message/

Many people have requested this and I'll try again :)

I feel like this is one of the core functionalities that is missing from the Live components. That is just because of the promise that it says in the front page of Live Components "No javascript needed". :)

In my case I have filtering page that consists of actors. Everyone of them have sample selector with multiple samples and of course these are children of actor components. Entities also have relations. Then I have player component that is outside of the content DOM to keep it in every page with Turbo.

I select sample from one of the sample selectors and the push play button next to it. It emits to the player that it needs to play this specific sample. player pops up in the page and it has information about the sample, actor and plays it. Now I want to pause the sample from the player and I want to show in the sample selector that the audio is paused. My options:

  1. I can emit from the player live component to all sample selectors with a payload of actor id that pause has been pressed, check that id in the component php and change the play to pause. (request to all sample selectors, no js)
  2. Use the id of the sample selector in custom stimulus controller in the audio player and target only one sample selector (one request, js)
  3. Define custom stimulus controller in sample selector to register listener for that component and emit to that listener from the player php. (one request, js)

Suggestions

Allow #[LiveListener('function', modifier: 'changeFunction')

This would add definition for the function so it can be emited to with function:modifier (or without modifier part). Basically it just registers more listeners for one component.
In my case the modifier function could return the actor Id so that I could emit from the player to one sample selector. Example: emit('pause:'.$sample->getActor()->getId())

Add required example stimulus controller(s) to documentation and why it is recommended way.

Documentation does not have this case and time to time people seem to ask how to do this because they do not want to do multiple requests.

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