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

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
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
armanm
I know zero downtime deployment can mean different things depending on your application and what your users can tolerate so expectations ...
New
markdev
What are the best beginner resources for learning Elixir and OTP (not Phoenix) in 2018?
New
Besto
I've been trying to start learning Elixir for a couple of weeks while I develop a tiny project I have on node.js, but every time I try to...
New
shansiddiqui94
Hello, I have an interview coming up and I seem to have forgotten important concepts of Elixir. So I was wondering if you guys know of a...
New
koen_vb
Hi, I was looking for a pointer of how I could most easily start with phoenix regarding deploying it to something like linode or google c...
New
venomnert
Background I have been a backend elixir developer for about 3 years now. I have been mainly working on simple CRUD applications. Context...
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
shansiddiqui94
Greetings Elixir Developers, My name is Daniel, and I am taking my first step to learn all about the Elixir language. Currently I have a...
New

Other popular topics Top

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
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
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

We're in Beta

About us Mission Statement