aboutsummaryrefslogtreecommitdiff
path: root/examples/helloworld/src/main/kotlin/com/example/Main.kt
diff options
context:
space:
mode:
Diffstat (limited to 'examples/helloworld/src/main/kotlin/com/example/Main.kt')
-rw-r--r--examples/helloworld/src/main/kotlin/com/example/Main.kt41
1 files changed, 41 insertions, 0 deletions
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
+}
+