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 Slide

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

    View Slide

  3. Kotlin
    IS IT A THING?

    View Slide

  4. GREAT AT
    ANDROID!

    View 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 Slide

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

    View Slide

  7. Kotlin/js

    View Slide

  8. INSTALL KOTLIN
    brew install kotlin

    View Slide

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

    View Slide

  10. 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 Slide

  11. 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 Slide

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

    View Slide

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

    View Slide





  14. Console Output






    THE KOTLIN STANDARD LIBRARY IS ALSO ON NPM!

    View Slide

  15. HELP

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide