aboutsummaryrefslogtreecommitdiff
path: root/examples/showcase/src/main/kotlin/com/example/Main.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-01-29 21:03:34 +0100
committerRobert Jaros <rjaros@finn.pl>2018-01-29 21:03:34 +0100
commit2c7ca3f8808935fc0c56458dca54f7bf417141f7 (patch)
tree68d02115d3cc0467f825560f2b65a9591e5d78bc /examples/showcase/src/main/kotlin/com/example/Main.kt
parentb43764a2088912162ed5e8df2f6da7d2598fb1a3 (diff)
downloadkvision-2c7ca3f8808935fc0c56458dca54f7bf417141f7.tar.gz
kvision-2c7ca3f8808935fc0c56458dca54f7bf417141f7.tar.bz2
kvision-2c7ca3f8808935fc0c56458dca54f7bf417141f7.zip
Showcase example
Diffstat (limited to 'examples/showcase/src/main/kotlin/com/example/Main.kt')
-rw-r--r--examples/showcase/src/main/kotlin/com/example/Main.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/showcase/src/main/kotlin/com/example/Main.kt b/examples/showcase/src/main/kotlin/com/example/Main.kt
new file mode 100644
index 00000000..98c94f25
--- /dev/null
+++ b/examples/showcase/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): String
+
+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("showcase") == null) return null
+ val application = Showcase()
+ @Suppress("UnsafeCastFromDynamic")
+ application.start(state?.appState ?: emptyMap())
+ return application
+}
+