I'm using Phlex with a new Hanami 2 app. Hanami has a quite great DI system. This system gives me an instance of my dependencies when I load them into my classes.
Since I'm getting an already instantiated object I can't pass args to the object without doing something weird.
I'm rendering my partials with the help of the render method. To pass the arguments down to my object I created a monkey patch that uses the already existing kwargs parameter of the render method and passes this to the components call method.
def render(renderable, *args, **kwargs, &block)
case renderable
when Phlex::HTML
renderable.call(@_target, view_context: @_view_context, parent: self, **kwargs, &block) # HERE
when Class
if renderable < Phlex::HTML
renderable.call(@_target, view_context: @_view_context, parent: self, **kwargs, &block) # AND HERE
end
else
raise ArgumentError, "You can't render a #{renderable}."
end
nil
end
Is there a interest to merge this into Phlex? If not, could you please provide another way of passing arguments to my objects beside instantiation.
I'm using Phlex with a new Hanami 2 app. Hanami has a quite great DI system. This system gives me an instance of my dependencies when I load them into my classes.
Since I'm getting an already instantiated object I can't pass args to the object without doing something weird.
I'm rendering my partials with the help of the
rendermethod. To pass the arguments down to my object I created a monkey patch that uses the already existingkwargsparameter of the render method and passes this to the componentscallmethod.Is there a interest to merge this into Phlex? If not, could you please provide another way of passing arguments to my objects beside instantiation.