Greetings all,
I’ve just pushed a Kotlin wrapper for React up to github (https://github.com/andrewoma/reakt).
It’s a proof of concept at this point, but it does have a fully working TodoMVC example.
As it’s my first experience with using the JavaScript backend, I thought I’d share my thoughts (and hopefully get some help).
The Good
- It works! React doesn’t make inter-operating easy, but I’ve found a work-around in all cases. e.g. React substitutes the this pointer to different types, uses complicated factories and doesn’t understand properties defined in prototypes.
- Kotlin is expressive enough to build a typesafe HTML builder. e.g. https://github.com/andrewoma/reakt/blob/master/src/todo/components/TodoItem.kt
- Delegated properties saved the day - they allowed me to store attributes directly on an underlying JavaScript object for interoperation with React.
- The IDE is remarkably responsive - there’s been massive improvements here - great work!
- The JS backend seems almost complete (couldn’t use enums, nested classes within class objects, or suppress annotations inline)
- Source maps support is awesome
The Bad
- Compilation times blow out fairly quickly (14s at present). Admittedly, the project does model the entire DOM. Will incremental compilation ever be possible for JavaScript?
- The lack of documentation and/or examples on the JavaScript tool chain
- Having to stick suppress("UNUSED_PARAMETER") on native methods.
- Name mangling doesn't make inter-operation easy. e.g. why shouldComponentUpdate_wn2jw4$ and not shouldComponentUpdate when it's not overloaded?
- Source maps support seems a bit buggy. It's hit or miss as to whether the line numbers are correct.
- I had to mangle the source maps to replace file://... references to http://... for Chrome to read them for security reasons.
- Nullity on signatures seems patchy. e.g. document.getElementById() and String.match() are both incorrectly marked as NotNull.
- I had to fall back to native JavaScript at times and there's no way of doing it without creating a companion JavaScript file (nothing like GWT's inline JavaScript snippets).
- Kotlin isn't quite expressive enough to define an HTML builder without boilerplate - I ended up falling back to code generation.
The Questions
- How does the standard library work with in with the JS backend? Creating a Kotlin (JavaScript) project in IntelliJ doesn't include the standard library. So far, I've got away without it, but can be included? (the maven build seems to automatically include it).
- How do I build and distribute a Kotlin Javascript library? Is it distributed as a source jar (GWT style)? It seems like there's a Kotlin source stub for the standard library. What generates it?
- How are tests run? I noticed there's a QUnit asserter? Can I make use of any of this or is it just for the standard lib? (I have got Karma tests running with a little mangling, but is there an endorsed way?)
- How do I tell IntelliJ that a module is Kotlin (JavaScript) after project creation? e.g. importing a maven project defaults to Kotlin (Java) and I can't work out how to force it to JavaScript.
- Not really JS related, but is there a maven repository somewhere that has the TeamCity builds in it? I constantly get cornered by updating my plugin to the latest nightly and not finding anything compatible for gradle/maven builds.
Finally, you guys are doing a fanstastic job - I'm doing my best to sneak Kotlin into my office whenever I can. :-)
Cheers,
Andrew