DaAnalyst

DaAnalyst

Inspired by the today exchange with @josevalim regarding a particular maybe-LiveView-maybe-Alpine bug (see the links below) I’d like to open a discussion on the best way to proceed in future cases like this.

https://github.com/phoenixframework/phoenix_live_view/issues/2657

I agree with Jose’ that PETAL (LiveView+Alpine) users should have a single point of reference such as a single repository with just a README.md file where we could merge our knowledge base and best practices, a place that unlike various blogs around will have a history.

Does anyone know if such a repo exists already? If not, I can go about creating one.

In addition, maybe @AstonJ can make a special PETAL sub-category under Phoenix Forum.

Showing Posts 1 to 8

DaAnalyst

DaAnalyst OP

Delighted to see so much interest (3 likes so far)! </sarc>

Anyway, the LiveView-Alpine github organization and its integration knowledge-base repo can be found at the link below. It’s currently empty but I (we) will be adding content as we go.

https://github.com/liveview-alpine/integration

greven

greven

I went the Alpine route when LiveView was new and without any JS integration outside of Hooks, for micro interactions Alpine made so much sense (and I was familiar with Vue API which Alpine kinda of mimics).
I later dropped it in favour of just plain LiveView.JS usage and/or combined with Hooks.

Why? Well, because of the CSP (Content-Security Policy), reference: CSP — Alpine.js

In order for Alpine to be able to execute plain strings from HTML attributes as JavaScript expressions, for example x-on:click="console.log()" , it needs to rely on utilities that violate the “unsafe-eval” content security policy.

I’m not comfortable with the trade back nor with the CSP violation, so I preferred to go the %JS{} / Hook routes. :slight_smile:

Glad for your contribution, think that is a good idea. The Phoenix components PETAL framework makes use of Alpine, maybe it can also serve as inspiration for people following that route.

DaAnalyst

DaAnalyst OP

I get where you’re coming from, but I really don’t see how you can contrast Phoenix.LiveView.JS + LV hooks to Alpine.

Hooks can be helpful for achieving the kind of client-side behavior that is triggered by the hook events. Beyond that (i.e. trying to manage complex state with them) it’s becoming an overkill. I know because I did plenty of that (3 - 4 years ago) before I started using Alpine.

The JS module merely covers some very basic needs and cannot possibly replace the wide spectrum of Alpine application.

greven

greven

You are right, %JS can’t replace Alpine at all, and probably it never will. That is why we have hooks. I dont think hooks are overkill at all, simply a necessity and generally sprinkling some hooks are all we need in LV land. When hooks get co-located I think we really wont need Alpine at all.

But Alpine is very practical indeed inspite of the CSP violation.

DaAnalyst

DaAnalyst OP

Collocation will help organize them better, but it won’t solve what can and what can’t be done easily with them, that’s unless you find it acceptable to have more JS code then the template code with the hooks merely adding and removing the listeners which then invoke the JS code, for that’s the only way you can replace Alpine, all while reinventing the wheel over and again.

Speaking of which, have you tried replacing any of the following with the hooks (never mind not being “collocated”):

  • x-model + x-effect
  • x-timeago
  • x-intersect

I did some of those and, boy, do I not want to do stuff like that again with hooks.

Alpine is very practical, indeed. I’d compare it’s practicality relative to writing hooks as using tailwind relative to maintaining separate CSS/SCSS files.

cmo

cmo

I found managing compex state in Alpine a bit of a mess and moved to JS commands and hooks too. The interaction between a hook and liveview’s lifecycle is much easier to manage than liveview and alpine.

I never used the x- thingos you mentioned though. Not sure they were around back then.

DaAnalyst

DaAnalyst OP

There are some people reporting issues with using Alpine, but more often than not those originate from their lack of understanding how to do things correctly (hence this ongoing effort). Also, I have 0 issues with Alpine (except for performance issues) while working on a relatively large and very granular app (in terms of both LiveComponents and function components).

As for the x-thingos, what can I say, the requirements I got are quite demanding on the UX but admittedly not all apps may have such a case.

DaAnalyst

DaAnalyst OP

The initial entries are now available (in the README.md):

https://github.com/liveview-alpine/integration

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
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
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews