nseaSeb

nseaSeb

AcmeScript — Writing JS hooks as if I were still using Elixir

I’ve been having fun building a little something over the last few days: AcmeScript.

The idea started with something pretty simple: when working in Phoenix/LiveView, I really love the way code is written in Elixir… but as soon as I have to dive into a phx-hook, I switch back to JavaScript and lose a bit of that comfort. :sweat_smile:

So, I tried tweaking JS a bit.

For example:

pipe(
users,
Enum.filter((u) => u.active),
Enum.map((u) => u.name),
Enum.uniq()
)

Or:

getIn(state, ["user", "profile", "name"])
putIn(state, ["user", "profile", "name"], "Seb")

And for hooks, the idea is to have a slightly more convenient context:

createHook({
mounted(ctx) {
ctx.handle("something", (payload) => {
// ...
})

ctx.push("something_happened")
}
})

I also ended up including a few other things I frequently missed: ok/error, match, a little withDo, H/J, some DOM helpers, a client-side PubSub, etc.

Obviously, this isn’t an attempt to turn JavaScript into Elixir (well… maybe a little bit :grinning_face_with_smiling_eyes:).

The fun part is that it actually fits into very little code and can be used directly as an ES module, without a mandatory build step.

:backhand_index_pointing_right: GitHub - nseaSeb/acmescript: Helpers JS façon Elixir pour hooks LiveView et templates .heex · GitHub

I’d be curious to hear your thoughts: do you find this kind of helper pleasant to use, or am I simply trying to force JS to become Elixir against its will? :grinning_face_with_smiling_eyes:
Ideas and suggestions are welcome.

Showing Posts 1 to 4

jam

jam

Cool. Also you might be interested in https://hologram.page/

OndrejValenta

OndrejValenta

Or you might be interested in this, based on scope of you javascript and what it does. In my experience meddling with LiveView code is really not something you want to do

nseaSeb

nseaSeb OP

Thanks for the feedback! I agree — it really depends on the context and the choices you want to make.

To my mind, there are roughly three levels:

Level 1 — AcmeScript: small JS utilities with no build step, for cases where you genuinely need to write some “inline” JavaScript in a hook, but want to make that code a little more pleasant and Elixir-like.

Level 2 — lightweight declarative tools: things like Alpine, where you rely more on conventions and declarative patterns while staying very close to native JavaScript.

Level 3 — full-fledged frameworks: Svelte/React islands, Hologram, etc., with a build step and a proper application infrastructure.

Each approach solves a different problem.

Hologram and keen_phoenix_svelte are excellent examples of approaches that can make hooks unnecessary in many cases — which is a perfectly valid direction.

AcmeScript is deliberately much more modest: it’s simply a small JS helper library for the cases where you do need a hook. It can even be used as a foundation for building your own helpers.

So I don’t really see them as competing approaches — more like different points on the same spectrum.

nseaSeb

nseaSeb OP

Hey, I added classics hooks in a demo

— 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
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
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