A live reloader for Scenic. Once configured, when you edit a file the current root scene will be killed, when it is restarted it will use any new code currently in the running beam instance.
How it works:
- Uses exsync to watch the file system
- When you edit a file with your editor, exsync recompiles and reloads that beam file
exsync
notifiesscenic_live_reload
that files were reloadedscenic_live_reload
kills the currently displayed root scene- The OTP Supervisor for that scene restarts the scene with the updated code
In this demo I replace the text "World" with "Scenic", then change the color of the text to purple. Next I change the shape of the bezier line.
Note: the code running in the demo can be found at https://github.com/axelson/scenic_live_reload_demo
See also: scenic-starter-pack
Add scenic_live_reload
to your list of dependencies in mix.exs
:
def deps do
[
...
{:scenic_live_reload, "~> 0.3", only: :dev},
]
end
Add this configuration to your config.exs
:
case Mix.env() do
:dev ->
config :exsync,
reload_timeout: 150,
reload_callback: {ScenicLiveReload, :reload_current_scenes, []}
_ ->
nil
end
Then start your application with mix scenic.run
(or iex -S mix
), edit a file with your editor, and then you should see your change reflected.
NOTE: This currently relies on a private scenic api to get the root scene which may change in future Scenic releases