Users of Phoenix LiveView: is update/2, update/3 and send_update/3 confusing?

update/3 in the LiveView module updates the socket’s assigns (similar to Map.update!/3).

update/2 callback in LiveComponent module is invoked as part of the component’s lifecycle (if defined) and is also invoked (if defined) by send_update/3.

send_update/3 in the LiveView module updates a mounted component by invoking update/2.

Somebody new to the framework might get confused and have to remember which update is which.
A quick fix might be renaming the update/3 function to something like update_assign/3 if this is a real problem for newcomers.

I would like to know what other users of LiveView think.

You explained them in short sentences, so they are not that confusing?

I’d rather stick to simple and short words for function name. Let’s not go down the road of:

  • Very long name, a la Objective-C: [ NSDistributedNotificationCenter postNotificationName: ...]
  • Too cute a name, a la Perl: croak? cull?

Many Elixir users are non-native English speakers. I find simple but imprecise word much easier to remember than long name or uncommon words.


Good points about the naming principles. I shouldn’t have provided an example.
Maybe the right approach to the thinking is:

update/2 and update/3 have very different functionality but have the same name when using
LiveComponent. I know I was able to explain it but for a newcomer this can be I believe confusing.

1 Like