diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 843c82c..ea42dc2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,19 +13,20 @@ class ApplicationController < ActionController::Base end class ProxyStream + # see: https://turbo.hotwired.dev/reference/streams + STREAM_ACTIONS = %i[append prepend replace update remove before after refresh].freeze + STREAM_ACTIONS.each do |method| + define_method(method) do |*streamables, **attributes| + @elements << @turbo_stream.send(method, *streamables, **attributes) + end + end + attr_reader :elements def initialize(turbo_stream) @turbo_stream = turbo_stream @elements = [] end - - def append(*streamables, **attributes) - @elements << @turbo_stream.append(*streamables, **attributes) - end - - def replace(*streamables, **attributes) - @elements << @turbo_stream.replace(*streamables, **attributes) - end end + private_constant(:ProxyStream) end