Will ElixirScript become a good alternative of ELM for Phoenix projects?

As everybody knows ELM is a great choice for front-end, and it’s compiler is awesome. People using ELM report having thousands of lines of ELM code for years with zero runtime exceptions. But if ElixirScript becomes as mature as ELM, it will be preferred for Phoenix’s front-end, which is natural. When will it reach to that maturity, or is it already there?

1 Like

I challenge that assumption. For example not every Clojure backend has a ClojureScript frontend - especially if they are maintained by different teams. Granted there is the appeal of an isomorphic or universal stack - but a large part of the appeal of Elm, PureScript or BuckleScript is that any one of them is statically typed.

Also more often than not, people who adopt Elixir have already accepted the reality of polyglot programming as it is always emphasized that Elixir isn’t good at everything (but typically can easily inter-operate with other specialist tools and/or languages).

3 Likes

Uh, elm has tons of runtime exceptions, anything from user-input regex crashing to occasional bad dom manipulation to far far more. Heck, look in its bug tracker for endless reports of issues with its typing system, some API designs, etc… etc… ^.^;

But yeah, as for ElixirScript, it will be useful for occasional code injection (especially when combined with things like Drab no doubt!!), but I prefer static typing when at all possible, especially with hairy front-end code. (I use bucklescript there, as it is an actually well tested and battle-hardened type system unlike Elm’s)

2 Likes

The approach Elixirscript takes is a double edged sword. Elxirscript compiles Erlang AST to Javascript. This may or may not be what you want. You may wanto to transpile from Elixir to Javascsript directly.

1 Like

This approach does mean that it can compile the standard library if it is needed too though. :slight_smile:

3 Likes

Of course, and that’s an advantage, but if you want to direactly call functions on the server from the client you may want to embed literal elixir function calls in HTML event handlers which you may want to transpile into JS code that sends HTTP requests or channel messages.

2 Likes

Macro’s! ^.^

? It can’t be macros. Macros transform AST into AST. I need to output Javascript code. I basically match on the AST nodes and output customized JS.

I need to do it at compile time inside macro, of course lol.

I mean a macro to generate the ast to feed to elixirscript to generate the server-back-call for the function and/or expression you passed in? :slight_smile:

Not exactly. I write something like this in the template:

<button onclick='MyModule.my_function(x, "y", 1, %{a: 1, b: 2})'></button>

I turn this call into a JS call (converting the constants in the arguments into JSON serializeable values) that sends a channel message

[id, [x, "y", 1, {a: 1, b: 3}]]

where id is an automatically generated small integer that maps to the function on the server). I intercept the message with an automatically generated “router” and dispatch the arguments to the MyModule.my_function() on the server.

The things I support in the arguments are:

  1. variables (converted without change)
  2. strings
  3. numbers
  4. booleans
  5. lists
  6. maps

I convert them based on AST node transformations alone.

This allows you to pretend inside the template that you can call normal Elixir functions and do things with the result. This has some problems regarding latency, of course, and may require some client-side locking of the UI. I’m still on the fence on whether this is a good approach. But it’s cool, and I’m still experimenting until I find a good API. This is mainly an experiment on how much I can push the notion of a thin client and thick server.

1 Like

Ah that is a cool style! Currently I just call out to real elixir functions/macro’s that do my embedding work for me, pretty basic in comparison. ^.^;

Your’s might be more powerful if you do something like allow it to pass in information from the pages DOM/javascript, perhaps the ^ and & and such operators would be useful there? :slight_smile:

You can pass Javascript variables unchanged. Or could if this system actually worked end to end, which it doesn’t.

1 Like