calebgasser

calebgasser

Up to date resources on learning LiveView?

I’ve been hopping around trying to learn Phoenix/Phoenix LiveView. Phoenix I think I finally got my head wrapped around but finding good resources on LiveView that is up-to-date is proving difficult. I always go to the documentation first but LiveView’s docs…are not really helping me that much.

I’ll give some examples of stuff I’m struggling with but I’d prefer some resources I can turn to so I don’t have to keep bothering people with questions.

I’m watching this video on creating a twitter clone with LiveView. It’s three years old so I expect some info to be outdated but that’s usually fine as when I run into something that doesn’t work I can usually refer to the docs.

Seems like Heex has changed a lot

In the video they are using stuff like;

<%= for post <- @posts do %>
 //...
<% end %>

but when opening up what I got from mix phx.gen.live I’m seeing things like

<.table
  id="posts"
  rows={@streams.posts}
  row_click={fn {_id, post} -> JS.navigate(~p"/posts/#{post}") end}
>
  <:col :let={{_id, post}} label="Username"><%= post.username %></:col>
//...

So, I tried to figure out what @streams was but couldn’t really find anything by searching for it in the docs that explains it. There is a stream/4 function but that doesn’t seem to be the same thing.

The generated code also seems to not really use <%= %> syntax and instead uses <.thing>< /.thing> or <:something></:something> syntax. I’m really not sure what’s happening here. I found one section in the docs that mentioned

Or when using function components:
<.show_name name={@user.name} />

But doesn’t go on to explain what a function component is. I’m not really sure how to iterate over my posts. When doing for post <- @posts I get back an %{id, post} struct but not sure how I pattern match on that in heex.

Also, no idea what things like <:col and <:action are doing. I know it’s refering to some kind of atom but do I need to use this syntax now? Should any HTML element I create be named as an atom? <:div> instead of <div>?

PubSub vs Stream?

In the video they use PubSub to do real time updates, this seems to have been replaced by streams. So like…what is a stream? I can’t really find anything in the docs. Playing with the code I’ve kind of figured out what they’re doing. There doesn’t seem to be any concrete examples or explanations on them in the docs though. Am I missing something or is it just supposed to be obvious and I’m dumb?

I’m sure I’ll run into more

This has just been what i’ve run into going through this one tutorial (which I haven’t even finished yet). I tried looking at some of the community resources they suggest in the github but a lot of those are behind expensive paywalls (listed as free though) or books you need to buy. I haven’t gone through the full list yet though, so I’ll keep searching.

Most Liked

cmo

cmo

Hello!

<.function_conponent_name ...> is a function component. You only use the dot for function components, not regular html tags.

https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html

<:slot_name ... > is a slot of a component.

https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#module-slots

Streams are a way of sending data to the client (frontend) and not keeping it in memory on the server. It is an alternative to assign, which will keep the data in memory on the server. It is not an alternative to pubsub.

https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#stream/4

Pubsub can be used in a liveview to subscribe to changes so you can update the webpage in real-time. Say you’re on a dashboard and you subscribe to updates to number of sales, the liveview can listen to these changes and update just the number of sales seen time it is changed (if the change is broadcast).

And yes, heex has changed a bit over the years.

Where Next?

Popular in Chat/Questions Top

ariandanim
Hello all, I am still learning Elixir, then go into Phoenix, i am try search in google but find the programming phoenix 1.4, another for...
New
lc0815
hello from a real frustrated newbe… I’m reading this article Full-Stack React With Phoenix (Chapter 3 | Introduction to Phoenix) by mich...
New
dopomecana
The title of this topic may sound silly at the first glance. But why I trying to ask you guys is how to go to the next level? I am curre...
New
Fl4m3Ph03n1x
Background I am trying to recycle myself and improve my knowledge about Phoenix. With 1.7 now out, this seems like a good opportunity. W...
New
Chawki
hi,i’m new to programming world i had learned front-end( javascript,react.js) and i wanna learn a back-end programming language i thought...
New
asfand
Hi Everyone, I am a student and know basics of web development, used some php and ruby, but I am not an expert in any. I want to learn E...
New
Santheepkumar
Hi all, I am a Fullstack JS developer for last 2 years. I need a good guide to learn elixer. Any suggestions please
New
Twfo326
As a novice dev I’m trying to keep the curriculum as lean as possible. My requirements are modest: build simple CRUD apps with Phoenix...
New
Allyedge
So, I want to get an Elixir book, but don’t know which one to get. Both Programming Elixir 1.6 and Elixir in Action looks interesting, b...
New
Fl4m3Ph03n1x
Background Hey guys, recently I bought a book on TDD that I am reading. The books is really nice and has some really juicy things on arch...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
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
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement