i-n-g-m-a-r
A %Phoenix.LiveView.Socket{} is not a %Phoenix.Socket{} yet both are called socket.
Would it be better to call a Phoenix.LiveView.Socket struct a live_socket ?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Names are always contextual. In the context of a live view module the
%Phoenix.Socket{}is never accessible, so you don’t need to distinguish the live socket you have from an ordinary phoenix socket. In a similar way, we always refer to a%Plug.Conn{}asconneven though there is also a cowboy connection out there making the request work. The cowboy connection isn’t really accessible in the context of a plug, soconnhas plenty of context and there’s no ambiguity.i-n-g-m-a-r
To interpret contextual names it’s necessary to be aware of the particular context which is not always easy when there’s many contexts and you’re not actually working on the module you’re looking at.
When names are self explanatory there’s no need to figure anything out.
Explicitness really is the only thing Python has over Elixir in my opinion.
sb8244
I’m going to agree with @benwilson512 here. The point of not exposing
lv_socketvsphx_socketis that it doesn’t really matter in the LiveView itself. As a public consumer of LiveView, you shouldn’t need to worry about what the Socket is. If Phoenix wanted to swap out the implementation of Socket completely, they could do so and it wouldn’t affect you.Phoenix itself does distinguish between the types of sockets. You can find an example in the LiveView source code. I think this is interesting because it shows that explicitness is being prioritized where important, and removed where it’s not important. If you are curious about how the sausage is made, then the source code is very accessible. This is a very pragmatic approach, imo.
It would be helpful to have more examples here. I’ve generally felt like Elixir as a language is really explicit. Libraries like Phoenix are good stewards of quality code, as well.
benwilson512
What concrete problem are you running in to?
i-n-g-m-a-r
To me
live_socketwould expose that I’m looking at a live view.Another example could be:
which is about assigns vs conn (.assigns)
i-n-g-m-a-r
The concrete problem is that I sometimes loose track of what is what.
For example today I was doing something like:
And then I don’t get any feedback saying
looks_like_assignswill never work,probably you mean something else.
(of course I should read the docs better)
benwilson512
Can you elaborate on how that connects to socket variable name conventions?
benwilson512
To address what feels like a different topic,
live_renderhaving different args thanrender, I think a PR validating the options tolive_renderwould be a great addition. It’s still very much a work in progress.i-n-g-m-a-r
Well that example doesn’t.
I was trying to give an example of explicitness that would help.
With regard to socket variable name conventions many times I will pass sockets to helper modules that aren’t using Phoenix.LiveView.
Then, when I want to assign things, I would call Phoenix.LiveView.assign directly.
Which doesn’t work when it’s not a live socket.
benwilson512
Right, if I have a module that has helpers and some are for live view and some are not, then in THOSE functions I would have the variable be named
live_socket. The context of the helpers is different from the context of a live view module. The caller of a function and the function argument don’t need to be exactly the same name. Type specs can be very helpful there too.