Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin JS: Is it a Thing?

Kotlin JS: Is it a Thing?

Alexey Buzdin

March 22, 2017
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

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

    View full-size slide

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

    View full-size slide

  3. Kotlin
    IS IT A THING?

    View full-size slide

  4. GREAT AT
    ANDROID!

    View full-size slide

  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

    View full-size slide

  6. https://github.com/gradle/gradle-script-kotlin

    View full-size slide

  7. INSTALL KOTLIN
    brew install kotlin

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  11. GENERATED CONTENT
    *.META.JS - METAINFORMATION FOR REFLECTION

    View full-size slide

  12. 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);

    View full-size slide





  13. Console Output






    THE KOTLIN STANDARD LIBRARY IS ALSO ON NPM!

    View full-size slide

  14. 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"
    }

    View full-size slide

  15. ALL LANGUAGE FEATURES IN
    KOTLIN 1.1 WORKS IN
    JavaScript!

    View full-size slide

  16. ALL JS LIBRARIES ARE
    AVAILABLE IN KOTLIN!
    Use ts2kt to convert type definitions
    http://definitelytyped.org

    View full-size slide

  17. THANK YOU!
    Q&A
    Follow me on Twitter @ALEXEYBUZDIN

    View full-size slide