Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Statically typed Angular with Kotlin
package angular.demo
import angular.*
object HelloWorldModule : Module("HelloWorld") {
val hello = constant("hello", "Hello")
val world: String by factory("world") {"World"}
}
object AppModule : Module("App",array(HelloWorldModule)) {
{
controller<AppScope>("AppController") {
phrase = HelloWorldModule.hello + ", " + HelloWorldModule.world
clickCount = 0
addClick = { clickCount++ }
watch("clickCount") { value ->
if (value == 5) {
clickCount = 0
}
}
}
controller<InnerScope>("InnerController") {
buttonText = "Click"
buttonClick = {
addClick()
}
}
}
}
native trait AppScope : Scope {
var phrase : String
var clickCount: Int
var addClick: ()->Unit
}
native trait InnerScope : AppScope {
var buttonText : String
var buttonClick : InnerScope.()->Unit
}
fun main(args: Array<String>) {
AppModule
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment