Packages

Phoenix Playground makes it easy to create single-file Phoenix applications.

Current section

Files

Jump to
phoenix_playground lib phoenix_playground code_reloader.ex
Raw

lib/phoenix_playground/code_reloader.ex

defmodule PhoenixPlayground.CodeReloader do
@moduledoc false
def reload(_endpoint, _options \\ []) do
if path = Application.get_env(:phoenix_playground, :file) do
case File.read(path) do
{:ok, contents} ->
old = Code.get_compiler_option(:ignore_module_conflict) == true
Code.put_compiler_option(:ignore_module_conflict, true)
Code.eval_string(contents, [], file: path)
Code.put_compiler_option(:ignore_module_conflict, old)
# ignore fs errors. (Seems like saving file in vim sometimes make it temp dissapear?)
{:error, _reason} ->
:ok
end
else
# in Livebook, path is nil
:ok
end
end
end