forked from hotwired/turbo-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turbo::Streams::TagBuilder can set targets attribute on stream tag
hotwired/turbo#113 allowed for multiple targets in turbo frame streams. This attempts to expose the feature to the Rails turbo_stream tag helper. Instead of a `target` which results in a call to `document.getElementById` on the JS level, a `targets` attribute will be passed into `document.querySelectorAll` I'm not 100% happy with the "API" to invoke it, but it's the best I could come up with. Feedback appreciated. The gist of it is the turbo stream tag builder helpers now accept a `target_multiple` keyword arg (default `false`). When set to `true` the end result of the tag will have a `targets` attribute instead of a `target` attribute. I purposfully did not touch the ActionCable-related part of the gem as I think its usecase is mostly geared to always updating one element at a time. Regardless, if it were to get this feature, I think it would be better in a separate pull request. For now, I think giving the developer the abiltiy to target multiple elements at once in the turbo stream response from a controller is ok for now.
- Loading branch information
Showing
5 changed files
with
92 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= turbo_stream.remove @message, target_multiple: true %> | ||
<%= turbo_stream.replace @message, target_multiple: true %> | ||
<%= turbo_stream.replace @message, "Something else", target_multiple: true %> | ||
<%= turbo_stream.replace "message_5", "Something fifth", target_multiple: true %> | ||
<%= turbo_stream.replace "message_5", target_multiple: true, partial: "messages/message", locals: { message: Message.new(record_id: 5, content: "OLLA!") } %> | ||
<%= turbo_stream.append "messages", @message, target_multiple: true %> | ||
<%= turbo_stream.append "messages", target_multiple: true, partial: "messages/message", locals: { message: Message.new(record_id: 5, content: "OLLA!") } %> | ||
<%= turbo_stream.prepend "messages", @message, target_multiple: true %> | ||
<%= turbo_stream.prepend "messages", target_multiple: true, partial: "messages/message", locals: { message: Message.new(record_id: 5, content: "OLLA!") } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters