Kotlin JS: Is it a Thing?

Kotlin JS: Is it a Thing?

12d6ff93ca25d366161efccadd81bbb2?s=128

Alexey Buzdin

March 22, 2017
Tweet

Transcript

  1. Kotlin/js IS IT A THING? Alexey Buzdin, MARCH 2017

  2. Me WRITING Mobile AND Java STUFF ORGANIZING events SPEAKING AT

    conferences TEACHING people
  3. Kotlin IS IT A THING?

  4. GREAT AT ANDROID!

  5. “She turned to the sunlight And shook her yellow head,

    And whispered to her neighbor: "Winter is dead.” - A.A. MILNE, When We Were Very Young https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin
  6. https://github.com/gradle/gradle-script-kotlin

  7. Kotlin/js

  8. INSTALL KOTLIN brew install kotlin

  9. Let’s create HelloKotlin.kt fun main(args: Array<String>) { println("Hello JavaScript!") }

  10. Let’s create HelloKotlin.kt fun main(args: Array<String>) { println("Hello JavaScript!") }

    Let’s compile it to javascript kotlinc-js -output out/sample-library.js -meta-info HelloKotlin.kt
  11. Let’s create HelloKotlin.kt fun main(args: Array<String>) { println("Hello JavaScript!") }

    Let’s compile transpile it to javascript kotlinc-js -output out/sample-library.js -meta-info HelloKotlin.kt
  12. GENERATED CONTENT *.META.JS - METAINFORMATION FOR REFLECTION

  13. if (typeof kotlin === 'undefined') { throw new Error(“Error loading

    module …”); } this['sample-library'] = function (_, Kotlin) { 'use strict'; var println = Kotlin.kotlin.io.println_s8jyv4$; function main(args) { println('Hello JavaScript!'); } _.main_kand9s$ = main; Kotlin.defineModule('sample-library', _); main([]); return _; }(typeof this['sample-library'] === 'undefined' ? {} : this['sample-library'], kotlin);
  14. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Console Output</title> </head>

    <body> <script type="text/javascript" src="node_modules/kotlin/kotlin.js"></script> <script type="text/javascript" src="out/sample-library.js"></script> </body> </html> THE KOTLIN STANDARD LIBRARY IS ALSO ON NPM!
  15. HELP

  16. Running with GRADLE buildscript { ext.kotlin_version = '1.1.1' repositories {

    mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: 'kotlin2js' repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" }
  17. ALL LANGUAGE FEATURES IN KOTLIN 1.1 WORKS IN JavaScript!

  18. ALL JS LIBRARIES ARE AVAILABLE IN KOTLIN! Use ts2kt to

    convert type definitions http://definitelytyped.org
  19. THANK YOU! Q&A Follow me on Twitter @ALEXEYBUZDIN