Browse Source

proxy_stream meta_programming

main
pvincent 4 days ago
parent
commit
4dd91e3782
  1. 17
      app/controllers/application_controller.rb

17
app/controllers/application_controller.rb

@ -13,19 +13,20 @@ class ApplicationController < ActionController::Base
end end
class ProxyStream 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 attr_reader :elements
def initialize(turbo_stream) def initialize(turbo_stream)
@turbo_stream = turbo_stream @turbo_stream = turbo_stream
@elements = [] @elements = []
end end
def append(*streamables, **attributes)
@elements << @turbo_stream.append(*streamables, **attributes)
end
def replace(*streamables, **attributes)
@elements << @turbo_stream.replace(*streamables, **attributes)
end
end end
private_constant(:ProxyStream)
end end
Loading…
Cancel
Save