What "assign" function is it in LiveView pages?

On LiveView pages usually there’ll be code similar to this:

    defmodule MyAppWeb.MyPageLive.Index do
      # ..........
      defp apply_action(socket, :edit, %{"id" => id}) do
        items = Repo.get!(MyData, id)
        # ........

        socket
        |> assign(:page_title, "Edit MyData")
        |> assign(:my_data, items)
      end

What assign() function is this? Where is it imported from precisely - from what module?

For there’re multiple modules in “deps/” that all have to do with Phoenix or LiveView and that all contain the definition ofassing(...) in them.

What version are you on? The latest has unified assign under Phoenix.Component

1 Like

The function can be found here. I think it is imported when you do the use Phoenix.{LiveView, Component, LiveComponent} in your AppWeb module.

1 Like