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

jace
I wanted to write a library for interacting with a Web API as a practical way of learning Elixir. However, there seem to be a lot of diff...
New
meraj_enigma
Hey, What’s a good resource to learn Microservices in Elixir/Phoenix? Is there any book/docs/Github repos that I can refer to? Thanks, -M
New
wolfiton
Question: Can someone recommend me some good resources on learning performance for phoenix elixir applications and a design pattern I sh...
New
armanm
I know zero downtime deployment can mean different things depending on your application and what your users can tolerate so expectations ...
New
pietrofxq
I’ve bought the following books: Programming Elixir 1.6 Programming Phoenix 1.4 Programming Ecto Functional Web Development with Elixir...
New
davearonson
I am looking for smallish problems to solve, using Elixir concepts beyond the basic syntax and concepts of Elixir as a language, such as ...
New
boddhisattva
Greetings everyone, At my current workplace we're evaluating different ways of building a microservices architecture for some parts rel...
New
phykos
In Ruby, which is very similar to Elixir I do this: def test yield end test do puts("sup there") end Here, the yield keyword will be...
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

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
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
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New

We're in Beta

About us Mission Statement