mix new MyApp --sup
creates a new app including a supervision tree. (docs) I’ve been going through the official guide (link) and discovered that its behavior has changed in 1.4. I’m trying to understand what’s going on and update the guide accordingly.
My main question is this: how can I edit the MyApp.Application
that seems to get automatically created by Mix when I can’t find the source file for it in the application?
I’d appreciate it if someone could explain to me what has changed or point me to discussions or documentation about this change.
Here’s details about the change.
Pre 1.4, mix new MyApp --sup
automatically included use Application
and default start/2
implementation in the main module file.
lib/my_app.ex
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# worker(MyApp.Worker, [arg1, arg2, arg3])
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
And it was loaded in mix.exs
like this:
def application do
[applications: [:logger],
mod: {MyApp, []}]
end
But in Elixir 1.4, it seems to create a separate MyApp.Application
module for it, while keeping the lib/my_app.ex
identical to the one created without the --sup
option.
lib/my_app.ex
defmodule MyApp do
@moduledoc """
Documentation for MyApp.
"""
@doc """
Hello world.
## Examples
iex> MyApp.hello
:world
"""
def hello do
:world
end
end
mix.exs
def application do
[extra_applications: [:logger],
mod: {MyApp.Application, []}]
end
The problem is, I can’t find the file for MyApp.Application
. I could locate Elixir.MyApp.Application.beam
in the _build
folder, but not its source file. If I wanted to change the behaviour of MyApp.Application.start/2
, how can I do it?