poops

poops

Documenting multiple `handle_event/3` functions in LiveView

What is the preferred way to document multiple handle_event/3 functions in a LiveView module?

I currently have different @doc strings associated with each function, since they each handle a different task. After upgrading to Elixir v1.11, I’m seeing “redefining @doc attribute previously set…” warnings.

Is it preferable to have all varieties of handle_event/3 documented in one large @doc string? I get that this makes sense for multiple functions that handles one task, but doesn’t make sense to me in this case.

Marked As Solved

voughtdq

voughtdq

If the functionality isn’t that different between them, sure it makes sense. If they are different and you need to actually generate public documentation for them, then you will probably need to break out into separate functions you can document.

def handle_event("widget_fizzled", params, socket), do: handle_widget_fizzled(params, socket)
def handle_event("fizzerator_gringled", params, socket), do: handle_fizzerator_gringled(params, socket)

@doc """
Handles the case when the widget was fizzled.
"""
def handle_widget_fizzled(_params, socket) do
  # ...
  {:noreply, socket}
end

@doc """
Handles the case when the fizzerator was gringled.
"""
def handle_fizzerator_gringled(_params, socket)
  # ...
  {:noreply, socket}
end

I see this pattern a lot in Erlang libraries - that is the handle*/[*] functions do very little inside the function body and actually just call out another function in the module. Then documentation can be provided on those functions instead.

Also Liked

poops

poops

Ah, gringle fizzle! Good call, I don’t hate this approach :slightly_smiling_face:

Where Next?

Popular in Questions Top

SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement