-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
[Turbo] Support custom TurboStreamResponse actions #2298
base: 2.x
Are you sure you want to change the base?
Conversation
13122e2
to
8514346
Compare
I think it should also work for |
This can be done by adding a generic |
@nicolas-grekas |
3e22298
to
66f7e36
Compare
With the incoming |
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Turbo] Add generic `<Turbo:Stream>` component | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Issues | #2298 (comment) | License | MIT I added a generic Turbo Stream component. To use it, you can do this: ```twig <twig:Turbo:Stream action="turbo_frame_reload" targets="#count-post" /> ``` The rendering is: ```twig <turbo-stream action="turbo_frame_reload" targets="#count-post"></turbo-stream> ``` Commits ------- f0ab499 [Turbo] Add generic `<Turbo:Stream>` component
I think they are complementary. I'd rather use the twig component syntax only in templates and stick to this helper on the php side, plus it's better to have consistent functionality in both, especially for people who dislike the twig component syntax. |
23a9740
to
03629f7
Compare
1683ace
to
bb8aeed
Compare
Looks good to me! Could you check the type of values and throw if not expected (a non-stringable object) ? |
I believe this is going to throw:
Or do you mean somewhere else ? |
So this is ready for merge then, right |
After some thinking, why don't we rename the |
Yeah, I was thinking about this when I renamed the one in TurboStreamResponse I don't really have a preference, both work, so I leave the choice to you |
Let's use action in both then (sorry for the late comment) |
bb8aeed
to
488e061
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last couple of minor suggestions..
Could you update the CHANGELOG in the src/Turbo repository ?
And let's merge this :)
8c46bf3
to
1b1aa6e
Compare
Ready to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @DRaichev !
1b1aa6e
to
4b62702
Compare
4b62702
to
6c3a3b7
Compare
Updated the changelog, now ready to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
The current implementation of TurboStream & TurboStreamResponse has no generic action (only the predefined turbo actions) and what's more the class is marked as final, which does not allow adding support for more actions. I think the wrap function should be public or have a public function "custom" that exposes the functionality (I've opted for the latter)
I really like this library: https://github.com/marcoroth/turbo_power
It adds additional simple actions. For example I use set/delete attributes to enable/disable UI elements
This change will allow people to use this or similar libraries, or even build their own custom actions if they want to.
There is no impact to the rest of the functionality or DX
There is a minor change to the wrap function, it now accepts an array of attributes instead of a string. It builds the string from the array of attributes, and adds a leading space. This aims to prevent errors, as the previous implementation needs the $attr argument to start with a blank space otherwise it would produce invalid html