Hi, I just published version 0.23.0 of Elixirscript.
Most of the changes are around JavaScript interop now that Elixirscript uses the Elixir compiler to compile and load files during compilation. This also means you can define macros in the same file now. Another bonus is that this release makes it a bit easier to share code between Elixir and Elixirscript.
That’s about it. Try it out and any feedback is always helpful.
I’ve been tempted to write a little webcomponent or polymer or so integration with it to see how it works, be a nice little bite-size thing to test with.
Nice! Let me know how it goes. I had written a small React example before for a local meetup, but never posted it online. I’m going to try to do that this week.
Hello I just published the latest version of Elixirscript. For a full list of the changes, take a look at the changelog The major changes in this version are:
Can select between ES, CommonJS, or UMD module formats for output
Can use and compile dependencies in mix projects (if dependency has the elixirscript compiler in its mix compilers)
Default input and output paths in mix projects
There is now an elixirscript organization with the projects that it uses. Also there is a newly created blog with the first post giving more details about the majors changes.
Finally, a gitter room was created for the project. The elixirscript channel on the elixir-lang slack still exists and I’ll still be there. The gitter room allows for integrations and keeps the history.
It’s Javascript typed bindings are just done via OCaml’s normal FFI system, it just all fit very well.
But yeah, I’d probably do something similar in Elixirscript. Last I saw Elixirscript you still did the JS.import bit (though now removed according to your just-now changelog ^.^), I’d probably do something like:
defjsmodule Underscore, import_name: "_" do
deffun blah/2
end
Or whatever, although you could add typing information like I’m doing in TypedElixir so you can cause compile-errors when interfaces are mis-used.
But yeah, OCaml’s FFI is just typing the interface, which the compiler then resolves to JS modules, it is very succinct and powerful and safe, as well as hard to borrow without having types in Elixir. ^.^
Ah that makes sense. Eventually I would like to get it to the point of requiring no JavaScript at all. It’s partially what the JS module is for right now, but could be built up to allow for more. The 2 systems that have impressed my so far are BuckleScript and Scala.js. But I guess both of those are type heavy examples. Anyways, I think there are somethings that can be done to get closer to that goal
@bryanjos: I saw docs at github and have some questions:
Do you support converting whole Elixir project into JavaScript app?
I mean not only specified directory, but also config, tests and others?
Is it possible to prefix JavaScript calls in Elixir code? :console.log("hello") => :js.console.log("hello"). This could conflict with libraries (I mainly think about :document).
I have a problem with last (4144) line: export default Elixir;, I got error message: SyntaxError: export declarations may only appear at top level of a module in Firefox Nightly and Uncaught SyntaxError: Unexpected token export in Chrome.
Right now only a specific directory. I haven’t tested converting config or tests.
Not possible right now, but something that could be up for discussion. I know clojurescript does something similar and it may be a good idea here. There is the “JS” modules which can be the jumping off point for that.
Try using the “umd” format instead. The default is “es” which isn’t supported by browsers just yet
Edit: I probably need to do a good sweep of the docs to make sure they are up to date
There is no support for defining classes and that’s on purpose. But if someone can find an idiomatic Elixir way to add classes I am all for it. Even though Elixirscript can’t create classes, it can instantiate them with JS.new/2. I hardly ever use classes in JavaScript so it’s a low priority for me.
You can’t change the output name now, but it is something that can be allowed now. I can make an issue to update the output parameter to allow for that.
Does not support method and module docs. I don’t see a reason to since this is a compile target.
start/2 is meant to be the “main” or entrypoint of your Elixirscript application. If you want to other modules outside of the Elixirscript scope then yes you would have to define start on them. or call __load(Elixir) directly or the module to load it and get an object returned with the functions defined on it.
Not all of the standard library is supported yet, but Logger may be a simple one to add. I’ll make an issue for it.
Good point I’ll update the docs. There used to be an implementation in the earlier days but since I started implementing the standard library in elixir I never added one back.
You could write a simple Macro that creates Module with some info, for example in module attributes.
defjsclass MyModuleName, :main do
# shortcut for define variable getter
defjsvariable :variable_name, :get
# shortcut for define another variable getter and setter
defjsvariable :another_variable_name, :both
def main do
# ...
end
end
that should be visible like:
defmodule MyModuleName do
@elixir_script_class_constructor_method_name :main
@elixir_script_is_class true
# shortcut for define variable getter
defjsvariable :variable_name, :get
# shortcut for define another variable getter and setter
defjsvariable :another_variable_name, :both
def main do
# ...
end
end