Add support for Turbo-streaming ViewComponents.#2595
Add support for Turbo-streaming ViewComponents.#2595joelhawksley wants to merge 1 commit intomainfrom
Conversation
| "messages", | ||
| action: :append, | ||
| target: "messages", | ||
| renderable: MessageComponent.serializable(message: self), |
There was a problem hiding this comment.
This is surprising. I thought serializable was producing an artifact for passing into ActiveJob, but that renderable was describing something that could render HTML for the front end. Isn't this mixing unrelated things?
There was a problem hiding this comment.
Conceptually, it's that we're making a renderable that can pass through the Active Job boundary by being serializable.
|
This definitely does what it says it does, and is very simple by simply intercepting Specifically as to project lifecycle, I think this API is fairly limiting and I wonder if it becomes difficult to extend. e.g. do the limitations become inherent to this implementation. I'd offer that one alternative would be to create a Proxy object that looked something like this: class ViewProxy
def initialize(target, **kwargs)
@target = target
@initialize_kwargs = kwargs
@with_component_kwargs ||= []
end
def with_component(**kwargs)
@with_component_kwargs << kwargs
end
# etc. whatever
def render
@target.new(@initialize_kwargs).then do |instance|
@with_component_kwargs.each { |k| instance.with_component(**kwargs) }
# etc.
end.render
end
end
module Serializable
def serializable(**kwargs)
ViewProxy.new(self.class, **kwargs)
end
end
MyComponent.serializable(foo: "bar").with_component(foo: "bar") |
Co-authored-by: Ben Sheldon <47554+bensheldon@users.noreply.github.com>
Closes #1106.