TwistingTwists

TwistingTwists

This is a thread to note down things/best practices encountered in LiveBeats App as I explore the source code.

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/controllers/user_auth.ex#L29

Found this usage of rescue/1

I’ve been meaning to handle Ecto errors myself. So this comes in handy for next time.

Showing Posts 1 to 10

cvkmohan

cvkmohan

Nice exercise @TwistingTwists

TwistingTwists

TwistingTwists OP

Who is current user in liveview app ? (even during redirects) More than just :fetch_current_user plug

live_beats/lib/live_beats_web/controllers/redirect_controller.ex at master · fly-apps/live_beats · GitHub

This has conn.assigns.current_user - without worrying that current_user might not exist.

above is possible because of plug :fetch_current_user here → live_beats/lib/live_beats_web/controllers/redirect_controller.ex at master · fly-apps/live_beats · GitHub

TwistingTwists

TwistingTwists OP

OneLiner For loop

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/live_helpers.ex#L494

Never seen a for loop like this before.

Practical render_slots

live_beats/lib/live_beats_web/live/profile_live.ex at master · fly-apps/live_beats · GitHub

Message passing other component from present one - JS.push

live_beats/lib/live_beats_web/live/profile_live.ex at master · fly-apps/live_beats · GitHub
“switch_profile” is in player_live.ex
live_beats/lib/live_beats_web/live/player_live.ex at master · fly-apps/live_beats · GitHub

Pattern Matching - via two variables in function - elegant

matching if current user is same as profile user or any other case.

live_beats/lib/live_beats/accounts.ex at master · fly-apps/live_beats · GitHub

TwistingTwists

TwistingTwists OP

I think I should write @docs in a forked repo instead, no?

RudManusachi

RudManusachi

First of all, thank you for this initiative!

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/live_helpers.ex#L494

Never seen a for loop like this before.

I’d recommend to post a “permalink” to the line in the commit. That file was changed 7 hours ago. And looks like the link doesn’t point to the place you meant to.

10
Post #5
dorgan

dorgan

Protip: if you press Y while seeing a github file it replaces the url at the address bar with a permalink so you can copy that instead of scrolling and clicking copy permalink

13
Post #6
TwistingTwists

TwistingTwists OP

Will take care.
https://github.com/TwistingTwists/live_beats/commit/36a775819ec2604cfe883eab6d5b198ffb3b7cd1

Added comments in this forked repo for consistency!

sergio

sergio

Excellent thread. Pinging @slouchpie so we can comb through this lots of good nuggets!

TwistingTwists

TwistingTwists OP

" Explain for loop : "

for a for {key, %{metas: metas}} <- presences, into: %{} do

what does into: do?

as explained by @kartheek - from elixir-lang

must remember : A comprehension is made of three parts: generators, filters, and collectables.

kartheek

kartheek

it collects into %{} in this case

The codefrom live_beats app is transforming presences - adding users and meta to every key in the presences. Final result will be %{key1 => %{metas: <..>, user: <..> }, key2 => %{metas: <..>, user: <..> }}

Where Next? Top

Trending in Guides/Tuts Top

krasenyp
You probably already know that &lt;span&gt;{nil}&lt;/span&gt; in a HEEX template produces &lt;span&gt; &lt;/span&gt; when rendered. I fin...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews