Skip to content

Commit 7be0b54

Browse files
committed
Migrate to Kotlin 1.1
1 parent e8b8224 commit 7be0b54

File tree

6 files changed

+60
-54
lines changed

6 files changed

+60
-54
lines changed

githubCommits.iml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="kotlin-language" name="Kotlin">
5+
<configuration version="2" platform="JavaScript ">
6+
<compilerSettings />
7+
<compilerArguments>
8+
<option name="languageVersion" value="1.1" />
9+
<option name="apiVersion" value="1.1" />
10+
</compilerArguments>
11+
</configuration>
12+
</facet>
13+
</component>
314
<component name="NewModuleRootManager" inherit-compiler-output="true">
415
<exclude-output />
516
<content url="file://$MODULE_DIR$">
@@ -9,5 +20,4 @@
920
<orderEntry type="sourceFolder" forTests="false" />
1021
<orderEntry type="library" name="KotlinJavaScript" level="project" />
1122
</component>
12-
</module>
13-
23+
</module>

src/declarations/arrayExt.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@file:Suppress("unused")
22

3-
package kotlin.js.array.ext
3+
package kotlinjs.array.ext
44

5-
@native
6-
fun <T> Array<T>.push(e: T): Unit = noImpl
5+
@Suppress("NOTHING_TO_INLINE")
6+
inline fun <T> Array<T>.push(e: T): Unit = asDynamic().push(e)
77

8-
@native
9-
fun <T> Array<T>.sort(comparator: (T, T) -> Int): Unit = noImpl
8+
@Suppress("NOTHING_TO_INLINE")
9+
inline fun <T> Array<T>.sort(noinline comparator: (T, T) -> Int): Unit = asDynamic().sort(comparator)

src/declarations/d3.kt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
package d3
44

5-
@native
6-
object d3 : Selectors<Any> {
7-
val scale: ScaleBase = noImpl
5+
external object d3 : Selectors<Any> {
6+
override fun select(selector: String): Selection<Any>
7+
override fun selectAll(selector: String): Selection<Any>
88

9-
fun <T> max(arr: Array<T>): Int = noImpl
10-
fun <T> max(arr: Array<T>, map: (v: T) -> Int): Int = noImpl
9+
val scale: ScaleBase
10+
11+
fun <T> max(arr: Array<T>): Int
12+
fun <T> max(arr: Array<T>, map: (v: T) -> Int): Int
1113
}
1214

13-
@native
14-
interface Selectors<D> {
15-
fun select(selector: String): Selection<D> = noImpl
16-
fun selectAll(selector: String): Selection<D> = noImpl
15+
external interface Selectors<D> {
16+
fun select(selector: String): Selection<D>
17+
fun selectAll(selector: String): Selection<D>
1718
}
1819

19-
@native
20-
interface Selection<D> : Selectors<D> {
20+
external interface Selection<D> : Selectors<D> {
2121
fun attr(name: String): String
2222
fun attr(name: String, value: Any): Selection<D>
2323
fun <R> attr(name: String, valueFunction: (data: D) -> R): Selection<D>
@@ -29,17 +29,17 @@ interface Selection<D> : Selectors<D> {
2929
fun <R> classed(name: String, valueFunction: (data: D, index: Int) -> R): Selection<D>
3030

3131
fun style(name: String): String;
32-
fun style(name: String, value: Any, priority: String? = null): Selection<D>;
33-
fun <R> style(name: String, valueFunction: (data: D) -> R, priority: String? = null): Selection<D>;
34-
fun <R> style(name: String, valueFunction: (data: D, index: Int) -> R, priority: String? = null): Selection<D>;
32+
fun style(name: String, value: Any, priority: String? = definedExternally): Selection<D>
33+
fun <R> style(name: String, valueFunction: (data: D) -> R, priority: String? = definedExternally): Selection<D>
34+
fun <R> style(name: String, valueFunction: (data: D, index: Int) -> R, priority: String? = definedExternally): Selection<D>
3535

36-
fun text(): String;
36+
fun text(): String
3737
fun text(value: Any): Selection<D>;
3838
fun text(valueFunction: (data: D) -> Any): Selection<D>
3939
fun <R> text(valueFunction: (data: D, index: Int) -> R): Selection<D>
4040

41-
fun <E> data(values: Array<out E>, key: ((data: E, index: Int?) -> String)? = null): UpdateSelection<E>
42-
fun <E> data(values: (data: Any, index: Int?) -> Array<E>, key: ((data: Any, index: Int?) -> String)? = null): UpdateSelection<E>
41+
fun <E> data(values: Array<out E>, key: ((data: E, index: Int?) -> String)? = definedExternally): UpdateSelection<E>
42+
fun <E> data(values: (data: Any, index: Int?) -> Array<E>, key: ((data: Any, index: Int?) -> String)? = definedExternally): UpdateSelection<E>
4343

4444
fun append(name: String): Selection<D>
4545

@@ -49,29 +49,27 @@ interface Selection<D> : Selectors<D> {
4949
fun <R> on(eventName: String, listener: (data: D, index: Int) -> R, capture: Boolean): Selection<D>
5050
}
5151

52-
@native
53-
interface UpdateSelection<D> {
52+
external interface UpdateSelection<D> {
5453
fun enter(): EnterSelection<D>
5554
}
5655

57-
@native
58-
interface EnterSelection<D> {
56+
external interface EnterSelection<D> {
5957
fun append(name: String): Selection<D>
6058
}
6159

62-
@native
63-
interface ScaleBase {
60+
external interface ScaleBase {
6461
fun linear(): LinearScale;
6562
}
6663

67-
@native
68-
interface QuantitiveScale : Function1<Any, Any> {
64+
/// ???
65+
external interface QuantitiveScale/* : Function1<Any, Any>*/ {
6966
fun domain(values: Array<out Any>): QuantitiveScale
7067
fun domain(): Array<Any>
7168

7269
fun range(values: Array<out Any>): QuantitiveScale
7370
fun range(): Array<Any>
71+
@nativeInvoke
72+
operator fun invoke(a: Any): Any
7473
}
7574

76-
@native
77-
interface LinearScale : QuantitiveScale
75+
external interface LinearScale : QuantitiveScale

src/declarations/jQueryExt.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
package jquery
44

5-
@native("\$")
6-
val jq: JQuery = noImpl
5+
@JsName("\$")
6+
external val jq: JQuery
77

8-
@native
9-
fun <T> JQuery.getJSON(url: String, callback: (data: T, status: String, jqXHR: Any) -> Unit): Unit = noImpl
8+
/// TODO noinline
9+
@Suppress("NOTHING_TO_INLINE")
10+
inline fun <T> JQuery.getJSON(url: String, noinline callback: (data: T, status: String, jqXHR: Any) -> Unit): Unit = asDynamic().getJSON(url, callback)
1011

11-
@native
12-
fun JQuery.show(): JQuery = noImpl
13-
@native
14-
fun JQuery.hide(): JQuery = noImpl
12+
@Suppress("NOTHING_TO_INLINE")
13+
inline fun JQuery.show(): JQuery = asDynamic().show()
14+
15+
@Suppress("NOTHING_TO_INLINE")
16+
inline fun JQuery.hide(): JQuery = asDynamic().hide()

src/githubApi.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
package github.api
22

3-
@native
4-
interface CommitInfo {
3+
external interface CommitInfo {
54
val html_url: String
65
val sha: String
76
val commit: GitCommitInfo
87
val author: GithubUser?
98
}
109

11-
@native
12-
interface GitCommitInfo {
10+
external interface GitCommitInfo {
1311
val author: GitUser
1412
val committer: GitUser
1513
val message: String
1614
}
1715

18-
@native
19-
interface GithubUser {
16+
external interface GithubUser {
2017
val login: String
2118
val avatar_url: String
2219
}
2320

24-
@native
25-
interface GitUser {
21+
external interface GitUser {
2622
val name: String
2723
val email: String
2824
val date: String

src/main.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import jquery.getJSON
66
import jquery.hide
77
import jquery.jq
88
import jquery.show
9-
import java.util.*
10-
import kotlin.js.array.ext.push
11-
import kotlin.js.array.ext.sort
9+
import kotlinjs.array.ext.push
10+
import kotlinjs.array.ext.sort
1211

1312
val GET_KOTLIN_COMMITS = "https://api.github.com/repos/JetBrains/kotlin/commits?sha=master&per_page=100"
1413
val GET_KOTLIN_COMMITS_LOCAL = "/githubCommits/commits.json"
@@ -18,6 +17,7 @@ val DEFAULT_AVATAR = "https://assets.github.com/images/gravatars/gravatar-user-4
1817
class CommitStat(val authorName: String, val commitCount: Int)
1918

2019
fun main(args: Array<String>) {
20+
// TODO replace with fetch
2121
jq {
2222
jq.getJSON<Array<CommitInfo>>(GET_KOTLIN_COMMITS) { commits, status, jqXHR ->
2323
val commitsDiv = jq("#commits")
@@ -77,7 +77,7 @@ fun updateChart(commits: Array<CommitInfo>, name2id: Map<String, Int>) {
7777
data.sort { a, b -> b.commitCount - a.commitCount }
7878

7979
// Setup scale
80-
val x: (Any) -> Any = d3.scale.linear()
80+
val x = d3.scale.linear()
8181
.domain(arrayOf(0, max))
8282
.range(arrayOf(0, 420))
8383

0 commit comments

Comments
 (0)