Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for broadcast methods to accept a renderable (#364)
* Allow for broadcast methods to accept a renderable Rails supports [rendering of objects](https://edgeguides.rubyonrails.org/layouts_and_rendering.html#rendering-objects) such as [ViewComponents](https://github.com/github/view_component), but this support doesn't seem to be available in Turbo. This is just a stake in the sand for exploring the option to render a `renderable` in addition to `html` and `partial`. This should allow for the following API call: ```ruby message.broadcast_update_to(:messages, target: "message-count", renderable: MessagesCountComponent.new(count: Message.count)) ``` where `MessagesCountComponent` is a supported Rails rendering object such as a ViewComponent. It turns out that Rails does accept a long form argument for rendering objects: `renderable`. The only gotcha is that it [renders the layout by default](rails/rails#39869), causing the layout to be duplicated. This change explicitly prevents the layout from being rendered in the call to `ApplicationController.render` to prevent that duplication from happening. * Remove reliance on ViewComponent library * Update test to utilize #assert_broadcasts_text * Add an example for rendering an object * Use less confusing name for test component * Remove unnecessary layout argument This isn't necessary since its set within: app/models/concerns/turbo/broadcastable.rb --------- Co-authored-by: Joshua Klina <jklina@joshuas-mbp.lan>
- Loading branch information