mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-16 04:46:46 +08:00
ac5a71bf85
* Multiplex initialization of JS views * Show timeout message when JS view data fails to load * Refactor JS view channel * Update tests
32 lines
911 B
Elixir
32 lines
911 B
Elixir
defmodule LivebookWeb.JSViewComponent do
|
|
use LivebookWeb, :live_component
|
|
|
|
@impl true
|
|
def update(assigns, socket) do
|
|
{:ok,
|
|
socket
|
|
|> assign(assigns)
|
|
|> assign_new(:timeout_message, fn -> "Not available" end)}
|
|
end
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<div id={"js-output-#{@id}-#{@js_view.ref}"}
|
|
phx-hook="JSView"
|
|
phx-update="ignore"
|
|
data-ref={@js_view.ref}
|
|
data-assets-base-path={Routes.session_path(@socket, :show_asset, @session_id, @js_view.assets.hash, [])}
|
|
data-js-path={@js_view.assets.js_path}
|
|
data-session-token={session_token(@js_view.pid)}
|
|
data-session-id={@session_id}
|
|
data-iframe-local-port={LivebookWeb.IframeEndpoint.port()}
|
|
data-timeout-message={@timeout_message}>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
defp session_token(pid) do
|
|
Phoenix.Token.sign(LivebookWeb.Endpoint, "js view", %{pid: pid})
|
|
end
|
|
end
|