-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Live reloading LiveViews without a hard refresh (#2323)
* render diffs without full page reload * accepts multiple topics-patterns * fix tests, add live reload test * subscribe just to live_view topic * Update mix.exs Co-authored-by: Chris McCord <chris@chrismccord.com>
- Loading branch information
1 parent
62c02b0
commit de1a2cd
Showing
23 changed files
with
249 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule Phoenix.LiveView.LiveReloadTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Phoenix.ConnTest | ||
import Phoenix.ChannelTest | ||
import Phoenix.LiveViewTest | ||
|
||
alias Phoenix.LiveReloader | ||
alias Phoenix.LiveReloader.Channel | ||
alias Phoenix.LiveView.LiveReloadTestHelpers, as: Helpers | ||
|
||
@endpoint Helpers.Endpoint | ||
@pubsub Phoenix.LiveView.PubSub | ||
|
||
setup config do | ||
ExUnit.CaptureLog.capture_log(fn -> | ||
start_supervised!(@endpoint) | ||
|
||
{:ok, _} = | ||
Supervisor.start_link([Phoenix.PubSub.child_spec(name: @pubsub)], | ||
strategy: :one_for_one | ||
) | ||
end) | ||
|
||
{:ok, _, socket} = | ||
LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{}) | ||
conn = Plug.Test.init_test_session(build_conn(), config[:session] || %{}) | ||
{:ok, conn: conn, socket: socket} | ||
end | ||
|
||
test "LiveView renders again when the phoenix_live_reload is received", %{conn: conn, socket: socket} do | ||
Phoenix.PubSub.subscribe(@pubsub, "live_view") | ||
|
||
Application.put_env(:phoenix_live_view, :vsn, 1) | ||
{:ok, lv, _html} = live(conn, "/live-reload") | ||
assert render(lv) =~ "<div>Version 1</div>" | ||
|
||
send(socket.channel_pid, {:file_event, self(), {"lib/test_auth_web/live/user_live.ex", :created}}) | ||
Application.put_env(:phoenix_live_view, :vsn, 2) | ||
|
||
assert_receive {:phoenix_live_reload, :live_view, "lib/test_auth_web/live/user_live.ex"} | ||
assert render(lv) =~ "<div>Version 2</div>" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.