-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcallbacks.ex
46 lines (38 loc) · 1.53 KB
/
callbacks.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
defmodule LiveDebugger.Utils.Callbacks do
@moduledoc """
This module provides functions to generate a list of callbacks for LiveViews and LiveComponents.
"""
alias LiveDebugger.Services.ModuleDiscovery
@common_callbacks [
{:render, 1},
{:handle_event, 3},
{:handle_async, 3}
]
@live_view_callbacks [
{:mount, 3},
{:handle_params, 3},
{:handle_info, 2},
{:handle_call, 3},
{:handle_cast, 2},
{:terminate, 2}
] ++ @common_callbacks
@live_component_callbacks [
{:mount, 1},
{:update, 2},
{:update_many, 1}
] ++ @common_callbacks
@doc """
Generates a list of callbacks for LiveViews and LiveComponents in form of MFA for the given module.
"""
@spec tracing_callbacks(ModuleDiscovery.live_modules()) :: [{module(), atom(), integer()}]
def tracing_callbacks(%{live_views: live_views, live_components: live_components}) do
Enum.flat_map(live_views, &live_view_callbacks/1) ++
Enum.flat_map(live_components, &live_component_callbacks/1)
end
defp live_view_callbacks(module) do
Enum.map(@live_view_callbacks, fn {callback, arity} -> {module, callback, arity} end)
end
defp live_component_callbacks(module) do
Enum.map(@live_component_callbacks, fn {callback, arity} -> {module, callback, arity} end)
end
end