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. ![]()
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
).
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.
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? ![]()
Ideas and suggestions are welcome.























