Valian / live_vue

End-to-end reactivity for Phoenix LiveView and Vue
https://hex.pm/packages/live_vue
MIT License
219 stars 11 forks source link

[Proposal]: Add shortcut version for the basic component properties #15

Closed vheathen closed 2 months ago

vheathen commented 3 months ago

It would be very helpful to have short version of the properties like v-socket and v-component.

For example:

v-component="Counter" -> @Counter v-socket={@socket} -> @={@socket} v-on:event="handler" -> @on:event="handler

I made a small change to make it work, and for me these renders 4 Counter components:

  def render(assigns) do
    ~H"""
    <div class="w-[350px] flex flex-col text-center h-full justify-center gap-2">
      <div>
        <.vue count={@count} v-component="Counter" v-socket={@socket} @on:inc={JS.push("inc_counter")} />
        <.vue count={@count} @Counter @={@socket} @on:inc={JS.push("inc_counter")} />

        <.Counter count={@count} v-socket={@socket} v-on:inc={JS.push("inc_counter")} />
        <.Counter count={@count} @={@socket} @on:inc={JS.push("inc_counter")} />
      </div>
    </div>
    """
  end

image

I can send PR if need.

Valian commented 3 months ago

I don't think it's a good idea. It might save a few chars but hurts readability. For example @=@socket seems very confusing.

Another reason is that @ has a special meaning in HEEX. That's the reason why I opted to use only v- prefix for special props (socket, ssr, and handlers).

Last - My personal preference is if a single thing can be done in a single way 😉

Do you agree?