From cd5885383ac25750bfcf11d19f9bed34d7a4c7f5 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 23 Jan 2019 11:00:47 +0100 Subject: Handlebars.js dependency upgrade + one helper extension function. --- src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/main/kotlin/pl') diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt b/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt index e47351ac..a826d343 100644 --- a/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt +++ b/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt @@ -21,8 +21,10 @@ */ package pl.treksoft.kvision.utils +import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.context.SimpleModule import kotlinx.serialization.json.JSON +import kotlinx.serialization.serializer import pl.treksoft.kvision.types.DateSerializer import kotlin.js.Date @@ -36,4 +38,11 @@ object JSON { install(SimpleModule(Date::class, DateSerializer)) } + /** + * An extension function to convert Serializable object to JS dynamic object + */ + @UseExperimental(ImplicitReflectionSerializer::class) + inline fun T.toObj(): Any { + return kotlin.js.JSON.parse(plain.stringify(T::class.serializer(), this)) + } } -- cgit