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

Stream Tag Builder: Support :renderable arguments #569

Merged

Conversation

seanpdoyle
Copy link
Contributor

When passed a valid :renderable option (like an object that responds to #render_in), treat that object as both the <turbo-stream> element's template contents and attempt to treat it as the target.

For example, consider a simplified "component" class:

class Component
  extend ActiveModel::Naming

  def initialize(id:, content:) = (@id, @content = id, content)
  def render_in(...) = @content
  def to_key = [@id]
end

component = Component.new(id: 1, content: "Hello, world")

turbo_stream.update(component) # => <turbo-stream action="update" target="component_1"><template>Hello, world</template></turbo-stream>

@seanpdoyle
Copy link
Contributor Author

cc @swanson, since this started as a conversation on the Hotwired discord.

@seanpdoyle seanpdoyle force-pushed the stream-tag-builder-support-renderable branch 4 times, most recently from bf65ac0 to c51fe26 Compare February 9, 2024 01:29
@seanpdoyle seanpdoyle force-pushed the stream-tag-builder-support-renderable branch 4 times, most recently from bb2981f to 6c04a1b Compare July 13, 2024 10:08
When passed a valid `:renderable` option (like an object that responds
to `#render_in`), treat that object as both the `<turbo-stream>`
element's template contents _and_ attempt to treat it as the target.

For example, consider a simplified "component" class:

```ruby
class Component
  extend ActiveModel::Naming

  def initialize(id:, content:) = (@id, @content = id, content)
  def render_in(...) = @content
  def to_key = [@id]
end

component = Component.new(id: 1, content: "Hello, world")

turbo_stream.update(component) # => <turbo-stream action="update" target="component_1"><template>Hello, world</template></turbo-stream>
```
@seanpdoyle seanpdoyle force-pushed the stream-tag-builder-support-renderable branch from 6c04a1b to 5038ed8 Compare September 16, 2024 14:55
@seanpdoyle
Copy link
Contributor Author

@brunoprietog are you able to review this?

Copy link
Contributor

@brunoprietog brunoprietog left a comment

Choose a reason for hiding this comment

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

Thanks @seanpdoyle!

@brunoprietog brunoprietog merged commit 1b60474 into hotwired:main Sep 16, 2024
15 checks passed
@seanpdoyle seanpdoyle deleted the stream-tag-builder-support-renderable branch September 16, 2024 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants