Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Kotlin IS IT A THING?

Slide 4

Slide 4 text

GREAT AT ANDROID!

Slide 5

Slide 5 text

“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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Kotlin/js

Slide 8

Slide 8 text

INSTALL KOTLIN brew install kotlin

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

GENERATED CONTENT *.META.JS - METAINFORMATION FOR REFLECTION

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Console Output THE KOTLIN STANDARD LIBRARY IS ALSO ON NPM!

Slide 15

Slide 15 text

HELP

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

ALL LANGUAGE FEATURES IN KOTLIN 1.1 WORKS IN JavaScript!

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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