kweb-core
kweb-core copied to clipboard
Support Kotlin compilation to Js
Bonjour :)
We recently wrote the following somewhere in our codebase:
private fun calendarGetValueSafeJs(id: String) =
"""
var date = $('#$id').calendar('get date');
if (!!date) {
date.setHours(0,0,0,0)
date.toISOString();
}
else
'';
""".trimIndent()
There's various tiny bits of js across our code, mostly one-liners calling some fomantic functinality. This got me thinking - What if we wrote this thing in Kotlin instead and compiled to Js? However, afaik, cross-compilation is something that we need the build tool's help with - we can't do it on the Kweb side.
Is this something to explore? Does someone have further insight?
Hi :)
We had a discussion about this a few months ago, regarding onImmediate Events. We talked about extracting the onImmediate Functions to a seperate file via a compiler plugin and then compiling that part to JS. At that time we thought about that, but never got to any concrete decisions. But maybe you want to research in that direction #76
It would be great if there was a better way to handle this kind of scenario so that people don't need to pepper their Kotlin code with JavaScript snippets.
My hope was that any such JavaScript could be handled within plugins like the Fomantic plugin, but I haven't done much work in this direction.
Using the Kotlin to JavaScript compiler is certainly worth considering - but my concern is that this might introduce a lot more pain than it alleviates because it would complicate the build process, and it would still be necessary to keep client and server-side code separate.
If we could identify common patterns where it's necessary to write this kind of embedded JavaScript a lot then perhaps we could provide a convenient but more specialized solution to address these usecases.
My hope was that any such JavaScript could be handled within plugins like the Fomantic plugin
It's a solid base, but a lot of stuff is still needed. I've been wanting to make some effort to open up some of our commonly used code - we have a lot of very useful stuff after running on Kweb for nearly a year. We actually just delivered our current project, so I may have some extra breathing room there, would be great to finally share that
If we could identify common patterns where it's necessary to write this kind of embedded JavaScript a lot then perhaps we could provide a convenient but more specialized solution to address these usecases.
Mostly it's calling fomantic functions using jquery selector to enrich basic components tbh. Nothing fancy, but random usages still grow a fair amount across a codebase
Mostly it's calling fomantic functions using jquery selector to enrich basic components tbh. Nothing fancy, but random usages still grow a fair amount across a codebase
That really could be just part of the fomantic plugin. Set of extension functions to deal with that. The plugin needs an update anyway since there are some classes missing.
If we could identify common patterns where it's necessary to write this kind of embedded JavaScript a lot then perhaps we could provide a convenient but more specialized solution to address these usecases.
I like this idea. TBH I kind of think about KWeb as fairly low level API, and imagine someone could build a framework with all the bells and whistles on top of it so the user wouldn't have to bother with HTML or JS. Just sticking some components together and be done - much like Flutter does.
Closing due to inactivity.