Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
fukuoka_kt_1
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
gupuru
July 05, 2017
Technology
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
fukuoka_kt_1
https://cdg.connpass.com/event/60570/
gupuru
July 05, 2017
More Decks by gupuru
See All by gupuru
ng-fukuoka-meetup-1
gupuru
0
430
AngularとAzureのCustom Vision Serviceを使って 画像認識サイトを作ってみた
gupuru
0
680
紙について少し詳しくなる10分間
gupuru
0
410
make bot, fun bot
gupuru
0
340
firebase勉強会資料
gupuru
3
790
iOS and Android SVG
gupuru
0
380
Firebaseについて
gupuru
1
230
BLEを使って、すれ違い通信をやってみるよー
gupuru
0
2.3k
HiyokoDeveloperMeeting
gupuru
1
150
Other Decks in Technology
See All in Technology
1000⼈規模のClaude Enterprise運⽤を「Oktaのグループ」と「Slack」に集約する
sansantech
PRO
0
460
Digital Credentials API × OpenID4VP ブラウザ完結型本人確認の実装知見(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
300
AI時代の「OAuth認証」にどう物申すか?(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
310
カーネルまで探検して理解するふたつの自動計装
sumiyae
0
330
atproto spaces概要
yamarten
0
110
ClaudeCodeでセキュリティ監視業務を半自動化_1年の運用でわかったAIに任せる設計の5つのポイント
kintotechdev
3
760
Claude Teamプランの コスト最適化を考える
rfdnxbro
0
770
Oracle AI Databaseデータベース・サービス: BaseDB/ExaDB-Dの可用性
oracle4engineer
PRO
1
930
Eight Engineering Unit 紹介資料
sansan33
PRO
3
8.3k
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
わたしが知り合いゼロの勉強会に 行けるようになるまで
r5ni4
2
820
アクセスキーが漏れた日にやるべきこと- 無効化の先にある本当の対応
kazzpapa3
0
350
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Site-Speed That Sticks
csswizardry
13
1.5k
Designing for Performance
lara
611
70k
Making the Leap to Tech Lead
cromwellryan
135
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Statistics for Hackers
jakevdp
799
230k
Designing Experiences People Love
moore
143
24k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
260
Exploring anti-patterns in Rails
aemeredith
3
470
Transcript
WebͰKotlinʂ Kotlin to JavaScript
About me ৽ݟ ߊฏ ϑϩϯτΤϯυͱػցֶशͷΤϯδχΞʹͳΖ͏ͱؤு͍ͬͯ ·͢(ʆɾωɾ´) • Twitter: @gupuru •
GitHub: gupuru
None
Kotlin 1.1ͰɺJavaScriptαϙʔτ͞Ε·ͨ͠ʂ JavaScript͕kotlinͰॻ͚·͢(ʆɾТɾ´) https://blog.jetbrains.com/jp/2017/03/01/739
ͪͳΈʹɺ͜Εࢼͨ͜͠ͱ͕͋Δਓɺ ڍखϊʢসʣ
͡ΊʹಋೖͩΑ(ʆɾТɾ´)
͜ͷ4ͭͷํ๏͕͋ΔΑ(ʆɾТɾ´) • Gradle • Maven • IntelliJ IDEA • Command
Line
IntelliJ IDEA
࠷ॳɺ͜Μͳײ͡ͷϓϩδΣΫτߏ͓ͩ(ʆɾТɾ´)
Build͢Δͱɺout͕Ͱ͖Δ͓(ʆɾТɾ´)
Buildͯ͠ɺͰ͖ͨϑΝΠϧΛHTMLଆͰݺΜͰ͋͛Δͱ͑Δ͓(ʆɾТɾ´) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ΘΜ͜</title> </head>
<body> <script type="text/javascript" src="out/production/wanko/lib/kotlin.js"></script> <script type="text/javascript" src="out/production/wanko/wanko.js"></script> </body> </html>
Γͷํ๏ɺ͜͜ݟͯ(ʆɾТɾ´) https://kotlinlang.org/docs/tutorials/javascript/kotlin-to-javascript/kotlin-to-javascript.html
࣮ࡍʹॻ͍ͯΈΔΑ(ʆɾТɾ´)
͜Μͳײ͡ʹॻ͘Α(ʆɾТɾ´) fun main(args: Array<String>) { val message = "͍͵ɺ͔Θ͍͍" println(message)
}
HTML͜Μͳײ͡(ʆɾТɾ´) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>wanko</title> </head>
<body> <script type="text/javascript" src="out/production/inukawaii/lib/kotlin.js"></script> <script type="text/javascript" src="out/production/inukawaii/inukawaii.js"></script> </body> </html>
͜Μͳײ͡ʹม͞Ε͍ͯΔΑ(ʆɾТɾ´) if (typeof kotlin === 'undefined') { throw new Error("Error
loading module 'kotlinJS'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'kotlinJS'."); } var kotlinJS = function (_, Kotlin) { 'use strict'; var println = Kotlin.kotlin.io.println_s8jyv4$; function main(args) { var message = '\u3044\u306C\u3001\u304B\u308F\u3044\u3044'; println(message); } _.main_kand9s$ = main; Kotlin.defineModule('kotlinJS', _); main([]); return _; }(typeof kotlinJS === 'undefined' ? {} : kotlinJS, kotlin);
গ͚ͩ͠ಈ͖͚ͭͯΈΔ͓(ʆɾТɾ´)
kotlin͓ͩ(ʆɾТɾ´) fun main(args: Array<String>) { val inputText: HTMLInputElement = document.getElementById("inputText")
as HTMLInputElement val button: HTMLButtonElement = document.getElementById("button") as HTMLButtonElement button.onclick = { window.alert(inputText.value) } }
HTML͓ͩ(ʆɾТɾ´) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ΘΜΘΜ</title> </head>
<body> <input id="inputText" type="text" value="" title="ͳʹ͔͍Εͨ·͑"> <button id="button">͋Βʔͱͩ͢Α</button> <script type="text/javascript" src="out/production/kotlinJS/lib/kotlin.js"></script> <script type="text/javascript" src="out/production/kotlinJS/kotlinJS.js"></script> </body> </html>
͜Μͳײ͡ม͞Ε͍ͯΔΑ(ʆɾТɾ´) if (typeof kotlin === 'undefined') { throw new Error("Error
loading module 'kotlinJS'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'kotlinJS'."); } var kotlinJS = function (_, Kotlin) { 'use strict'; function main$lambda(closure$inputText) { return function (it) { window.alert(closure$inputText.value); }; } function main(args) { var tmp$, tmp$_0; var inputText = Kotlin.isType(tmp$ = document.getElementById('inputText'), HTMLInputElement) ? tmp$ : Kotlin.throwCCE(); var button = Kotlin.isType(tmp$_0 = document.getElementById('button'), HTMLButtonElement) ? tmp$_0 : Kotlin.throwCCE(); button.onclick = main$lambda(inputText); } _.main_kand9s$ = main; main([]); Kotlin.defineModule('kotlinJS', _); return _; }(typeof kotlinJS === 'undefined' ? {} : kotlinJS, kotlin);
͞Βʹಈ͖͚ͭͯΈΔΑ(ʆɾТɾ´)
NodeͷαʔόΛͨͯͯΈΔ͓(ʆɾТɾ´)
package.json͓ͩ(ʆɾТɾ´) { "name": "wankoserver", "version": "1.0.0", "description": "", "main": "index.js",
"scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "gupuru", "license": "MIT", "dependencies": { "express": "^4.15.3", "kotlin": "^1.1.0" } }
gradle͓ͩ(ʆɾТɾ´) group 'wanko-express' version '1.0' 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" } compileKotlin2Js.kotlinOptions { moduleKind = "commonjs" outputFile = "node/index.js" }
kotlin͓ͩ(ʆɾТɾ´) external fun require(module:String):dynamic fun main(args: Array<String>) { println("wanwan start")
val express = require("express") val app = express() app.get("/", { req, res -> res.type("text/plain") res.send("wanko kawaii") }) app.listen(3000, { println("port: 3000") }) }
͜Μͳײ͡ม͞Ε͍ͯΔ͓(ʆɾТɾ´) (function (_, Kotlin) { 'use strict'; var println =
Kotlin.kotlin.io.println_s8jyv4$; function main$lambda(req, res) { res.type('text/plain'); return res.send('wanko kawaii'); } function main$lambda_0() { println('port: 3000'); } function main(args) { println('wanwan start'); var express = require('express'); var app = express(); app.get('/', main$lambda); app.listen(3000, main$lambda_0); } _.main_kand9s$ = main; Kotlin.defineModule('index', _); main([]); return _; }(module.exports, require('kotlin')));
ৄ͘͠ɺ͜͜Έͯ(ʆɾТɾ´) • https://github.com/miquelbeltran/kotlin-node.js
·ͱΊ
Kotlinָ͍͠(ʆŋТŋ´)
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ