TwistingTwists
Best Practices from LiveBeats App
This is a thread to note down things/best practices encountered in LiveBeats App as I explore the source code.
Found this usage of rescue/1
I’ve been meaning to handle Ecto errors myself. So this comes in handy for next time.
Most Liked
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
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.
mcrumm
Check out the Phoenix.HTML docs for Link.link/2– You can override the default (:get) link method. You can also provide a data-confirm attribute to prompt the user before following the link. This is all ancient UX stuff that you get when you include phoenix_html.js. ![]()
Almost certainly, but take a look at router.ex to be sure. You don’t want to put destructive actions behind a GET method (especially a public one) otherwise any request to the path will trigger the destructive action. Imagine a search engine spidering your delete links– it’s not ideal.
TwistingTwists
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
https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/profile_live.ex#L22
Message passing other component from present one - JS.push
https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/profile_live.ex#L25
“switch_profile” is in player_live.ex
https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/player_live.ex#L208
Pattern Matching - via two variables in function - elegant
matching if current user is same as profile user or any other case.
https://github.com/fly-apps/live_beats/blob/master/lib/live_beats/accounts.ex#L93
TwistingTwists
Who is current user in liveview app ? (even during redirects) More than just :fetch_current_user plug
This has conn.assigns.current_user - without worrying that current_user might not exist.
above is possible because of plug :fetch_current_user here → https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/controllers/redirect_controller.ex#L6








