Awesome!
I’d recommend this section of the docs. Also, at the risk of going too far, I think you’re doing yourself a disservice by using Surface while you’re getting started with and familiar with LiveView. I think Surface is awesome, but especially with LiveView 0.18+, much of the gap has been closed, and it will be much easier to find solutions/understand what’s going on if you don’t have to look in two places.
For instance, I think the Surface automatically delegates handle_event to live components, e.g.
# When using Surface
use Surface.LiveComponent
def render(assigns) do
~F"""
<button :on-click="some_event">Button</button>
"""
end
def handle_event("some_event", _, socket) do
...
end
# When using LiveView
use Phoenix.LiveComponent
def render(assigns) do
~H"""
<button phx-click="some_event" phx-target={@myself}>Button</button>
"""
end
def handle_event("some_event", _, socket) do
...
end
Notice that in the Phoenix.LiveComponent version, you have to explicitly target @myself for the event to go to the live component and not the parent live view. I believe Surface does that delegation automatically, but it obviously can’t delegate send(self(), ...) because it doesn’t have that level of control.






















