stimulusreflex / futurism

Lazy-load Rails partials via CableReady
MIT License
407 stars 19 forks source link

Futurize ViewComponents #36

Open julianrubisch opened 4 years ago

julianrubisch commented 4 years ago

Feature Request

Make futurism VC-proof

Is your feature request related to a problem?

It would be nice to be able to futurize VC just like partials.

rickychilcott commented 4 years ago

@julianrubisch would you want to pair on this some?

I'm not sure

<%= futurize ItemCardComponent.new(card, arbitrary: :value), extends: :div do %>
  <div class="spinner"></div>
<% end %>

would be supportable for an API unless you have some ideas about how we could hook into the view_component's instantiation step to capture raw arguments to deep transform them down the wire.

Something like the following could be workable:

<%= futurize component: ItemCardComponent, collection: @cards, extends: :div do %>
  <div class="spinner"></div>
<% end %>

which would call render(ItemCardComponent.with_collection(@cards)) under the hood. I suppose we could also expand it out to multiple <futurize-element> tags and handle the collection ourselves.

<%= futurize @card, component: ItemCardComponent, extends: :div do %>
  <div class="spinner"></div>
<% end %>

which would call: render(ItemCardComponent.new(@card) under the hood

I'm not sure the API we'd want to support for arbitrary parameters, maybe something like:

<%= futurize component: ItemCardComponent, locals: [@card, yes: :no], extends: :div do %>
  <div class="spinner"></div>
<% end %>

which would call: render(ItemCardComponent.new(@card, yes: :no) under the hood?

I think we have to strike a balance between fully supporting ViewComponents while also making it easy to transmit down the wire lazily. This could be a little tricky.

Also, as much as I'd like to be able to support something like:

<%= futurize_component @cards, extends: :div do %>
  <div class="spinner"></div>
<% end %>

to generate a collection of components, https://github.com/github/view_component/pull/129 supported to_component_class and it appears to be removed in https://github.com/github/view_component/pull/268

adambedford commented 3 years ago

👍 ++ For this feature. I'd love to see ViewComponent support. I'm just discovering this library in tandem with adopting components.