turbo-ruby icon indicating copy to clipboard operation
turbo-ruby copied to clipboard

Introduce a `StreamsBuilder` class

Open marcoroth opened this issue 3 years ago • 1 comments

Something like:

Turbo::StreamsBuilder.render do |turbo_stream|
  turbo_stream.append(...)
  turbo_stream.console_log(...)
  turbo_stream.morph(...)
end

Which would return one string like:

<turbo-stream action="append" ...>...</turbo-stream>
<turbo-stream action="console_log" ...>...</turbo-stream>
<turbo-stream action="morph" ...>...</turbo-stream>

or inside a model:

class Post < ApplicationRecord
  broadcast_turbo_stream_actions do |turbo_stream|
    turbo_stream.append(...)
    turbo_stream.console_log(...)
    turbo_stream.morph(...)
  end
end

marcoroth avatar Jan 08 '23 17:01 marcoroth

A POC of this has been implemented https://github.com/marcoroth/turbo_power-rails/pull/18, but in my option it makes more sense to have this class here in turbo-ruby.

marcoroth avatar Jan 08 '23 18:01 marcoroth