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

Hello Kotlin Js

85d7f0ae00c0cf1092dffcec966e3ae9?s=47 mattak
October 28, 2015

Hello Kotlin Js

My first impression of kotlin js.

85d7f0ae00c0cf1092dffcec966e3ae9?s=128

mattak

October 28, 2015
Tweet

More Decks by mattak

Other Decks in Programming

Transcript

  1. Kotlin Js ͞ΘͬͯΈͨ (PUBOEBKT  !NBUUBL

  2. Kotlinʁ

  3. ܕ҆શ, JVMݴޠ

  4. Androidʹ͓͚Δ SwiftͬΆ͍ݴޠ Androidք۾ͩͱ Better Javaͳ։ൃݴޠͱͯ͠ɺྲྀߦΓग़ͯ͠Δ

  5. Kotlin.jsͱ͸ʁ

  6. JVMܥͷAlt JSݴޠͰ͢ - ੩的型付け - 型安全、Null安全 - Kotlinライブラリが使える - クライアント/サʔバʔがKotlinで書ける

    - JetBrainsが作ってるのでEditorサポʔトが早い! ࢀߟIUUQZZZBOLCMPHTQPUKQLPUMJOBMUKTLPUMJOIUNM
  7. type safeʹ html͕͔͚ͨΓ͢Δ ࢀߟ: https://kotlinlang.org/docs/reference/type-safe-builders.html

  8. ࢖͍ํ - ύλʔϯ1. gradle -

  9. 1. SDKMan $ curl -s get.sdkman.io | bash

  10. 2. gradle install $ sdk use gradle 2.8

  11. buildscript { ext.kotlin_version = '1.0.0-beta-1038' repositories { mavenCentral() } dependencies

    { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: "kotlin2js" repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-js-library:$kotlin_version" } compileKotlin2Js.kotlinOptions.sourceMap = true compileKotlin2Js.kotlinOptions.outputFile = "${projectDir}/web/js/app.js" compileKotlin2Js.kotlinOptions.suppressWarnings = true compileKotlin2Js.kotlinOptions.verbose = true task copyJsFilesFromDependencies(dependsOn: build) { configurations.compile.each { File file -> copy { includeEmptyDirs = false from zipTree(file.absolutePath) into "${projectDir}/web/js/lib" include { fileTreeElement -> def path = fileTreeElement.path path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/")) } } } }
  12. buildscript { ext.kotlin_version = '1.0.0-beta-1038' repositories { mavenCentral() } dependencies

    { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: "kotlin2js" repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-js-library:$kotlin_version" } compileKotlin2Js.kotlinOptions.sourceMap = true compileKotlin2Js.kotlinOptions.outputFile = "${projectDir}/web/js/app.js" compileKotlin2Js.kotlinOptions.suppressWarnings = true compileKotlin2Js.kotlinOptions.verbose = true task copyJsFilesFromDependencies(dependsOn: build) { configurations.compile.each { File file -> copy { includeEmptyDirs = false from zipTree(file.absolutePath) into "${projectDir}/web/js/lib" include { fileTreeElement -> def path = fileTreeElement.path path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/")) } } } } 3. build.gradleॻ͘
  13. 4. ίʔυॻ͘

  14. 5. build͢Δ $ gradle clean build

  15. ίʔυ͕ग़ྗ͞ΕΔ

  16. σΟϨΫτϦߏ଄ $ find . -type f . ├── build.gradle ├──

    src │ └── main │ └── kotlin │ └── me │ └── mattak │ └── example │ └── kotlinjs │ └── main.kt └── web ├── index.html └── js ├── app.js ├── app.js.map └── lib ├── kotlin.js └── stdlib.meta.js
  17. ࢖͍ํ - ύλʔϯ2. homebrew -

  18. 1. brew install $ brew install kotlin

  19. 2. ίʔυΛॻ͘

  20. 3. convert͢Δ $ kotlinc-js main.kt -output main.js

  21. ίʔυ͕ग़ྗ͞ΕΔ

  22. ࢖͍ํ - ύλʔϯ3. ΏͱΓΉ͚ -

  23. try.kotlinlang.org

  24. ͦͷଞಛ௃

  25. Q. ϥϯλΠϜͷαΠζ ͱ͔େ͖͍ΜͰ͠ΐ͏ʁ

  26. A. ͏Μ $ ls -lha web/js/lib/ total 1912 drwxr-xr-x 4

    mattak staff 136B 10 27 17:39 . drwxr-xr-x 3 mattak staff 102B 10 27 17:39 .. -rw-r--r-- 1 mattak staff 804K 10 27 17:39 kotlin.js -rw-r--r-- 1 mattak staff 146K 10 27 17:39 stdlib.meta.js minifyͯ͠ͳ͍͚Ͳ jsͷϥΠϒϥϦͱͯ͠͸݁ߏαΠζͰ͔͍
  27. Q. JavaͷϥΠϒϥϦ ͱ͔ݺͼग़ͤΔͷʁ

  28. A. Ұ෦Αͼͩͤ·͢

  29. Q. طଘͷJsͷϥΠϒ ϥϦͱ࿈ܞͰ͖Δͷʁ

  30. A. native annotaionͰఆٛॻ͚͹ ͔ͭ͑ΔͬΆ͍ ࢀߟ: http://www.slideshare.net/mikeneck/kotlin-as-an-altjs/19

  31. Q. ࣮༻తʁ

  32. A. ͦΜͳ࣮༻త͡Όͳ͍͔΋ - js系の他の文化とあんまり親和してない - javaの資࢈もあんまり活きてない - Alt JSな型安全言語では、TypeScriptのほうが࣮用的かも

  33. ݁࿦ - ݱঢ়ͩͱ͓΋ͪΌͰɺ࣮༻తͰ͸ͳ͍͔΋ - ͋ͱࠓ͸npm͔Β؅ཧͰ͖ͳ͍Α - type safe html builderͱ͔͸໘നͦ͏

  34. αϯϓϧͱ͔ https://github.com/mattak/KotlinJsSample