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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 3 times, most recently from c5c65ac to bf65ac0 Compare February 8, 2024 21:45
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 bf65ac0 to c51fe26 Compare February 9, 2024 01:29
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.

None yet

1 participant