diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-01-21 20:36:13 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-01-21 20:36:13 +0100 |
commit | 7e095b7322c7dc831e8e3481848257dcda99d467 (patch) | |
tree | 9c05d9f97ebf9c0af5b685a5bf4e75833f9ad667 /examples/helloworld/src/main | |
parent | db7eb7216e097b7f05fcad998be3dda2f4ce9af5 (diff) | |
download | kvision-7e095b7322c7dc831e8e3481848257dcda99d467.tar.gz kvision-7e095b7322c7dc831e8e3481848257dcda99d467.tar.bz2 kvision-7e095b7322c7dc831e8e3481848257dcda99d467.zip |
Hello World example
Diffstat (limited to 'examples/helloworld/src/main')
-rw-r--r-- | examples/helloworld/src/main/kotlin/com/example/Helloworld.kt | 32 | ||||
-rw-r--r-- | examples/helloworld/src/main/kotlin/com/example/Main.kt | 41 | ||||
-rw-r--r-- | examples/helloworld/src/main/web/index.html | 19 |
3 files changed, 92 insertions, 0 deletions
diff --git a/examples/helloworld/src/main/kotlin/com/example/Helloworld.kt b/examples/helloworld/src/main/kotlin/com/example/Helloworld.kt new file mode 100644 index 00000000..61e75482 --- /dev/null +++ b/examples/helloworld/src/main/kotlin/com/example/Helloworld.kt @@ -0,0 +1,32 @@ +package com.example + +import pl.treksoft.kvision.ApplicationBase +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.html.TAG +import pl.treksoft.kvision.html.Tag +import pl.treksoft.kvision.panel.FLEXDIR +import pl.treksoft.kvision.panel.FLEXJUSTIFY +import pl.treksoft.kvision.panel.FlexPanel +import pl.treksoft.kvision.utils.px + +class Helloworld : ApplicationBase() { + + override fun start(state: Map<String, Any>) { + val root = Root("helloworld") + val panel = FlexPanel(FLEXDIR.ROW, justify = FLEXJUSTIFY.CENTER) + val hello = Tag(TAG.DIV, "Hello world!", classes = setOf("helloworld")).apply { + marginTop = 50.px() + + } + panel.add(hello) + root.add(panel) + } + + override fun dispose(): Map<String, Any> { + return mapOf() + } + + companion object { + val css = require("./css/style.css") + } +} diff --git a/examples/helloworld/src/main/kotlin/com/example/Main.kt b/examples/helloworld/src/main/kotlin/com/example/Main.kt new file mode 100644 index 00000000..fba5f87a --- /dev/null +++ b/examples/helloworld/src/main/kotlin/com/example/Main.kt @@ -0,0 +1,41 @@ +package com.example + +import pl.treksoft.kvision.ApplicationBase +import pl.treksoft.kvision.core.KVManager +import pl.treksoft.kvision.module +import kotlin.browser.document + +external fun require(name: String): dynamic + +fun main(args: Array<String>) { + var application: ApplicationBase? = null + + val state: dynamic = module.hot?.let { hot -> + hot.accept() + + hot.dispose { data -> + data.appState = application?.dispose() + KVManager.shutdown() + application = null + } + + hot.data + } + + if (document.body != null) { + application = start(state) + } else { + KVManager.init() + application = null + document.addEventListener("DOMContentLoaded", { application = start(state) }) + } +} + +fun start(state: dynamic): ApplicationBase? { + if (document.getElementById("helloworld") == null) return null + val application = Helloworld() + @Suppress("UnsafeCastFromDynamic") + application.start(state?.appState ?: emptyMap()) + return application +} + diff --git a/examples/helloworld/src/main/web/index.html b/examples/helloworld/src/main/web/index.html new file mode 100644 index 00000000..8d540e95 --- /dev/null +++ b/examples/helloworld/src/main/web/index.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>KVision Showcase</title> + <script type="text/javascript" src="main.bundle.js"></script> + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> + <!--[if lt IE 9]> + <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> +</head> +<body> +<div id="helloworld"></div> +</body> +</html> |