Tomasz Krakowiak
03/31/2021, 7:04 AMTomasz Krakowiak
03/31/2021, 7:09 AMTomasz Krakowiak
03/31/2021, 9:29 AMTomasz Krakowiak
03/31/2021, 12:45 PMRobert Jaros
03/31/2021, 12:55 PMRobert Jaros
03/31/2021, 12:57 PMRobert Jaros
03/31/2021, 12:58 PMTomasz Krakowiak
03/31/2021, 12:59 PMTomasz Krakowiak
03/31/2021, 1:01 PMRobert Jaros
03/31/2021, 1:01 PMTomasz Krakowiak
03/31/2021, 1:02 PMTomasz Krakowiak
03/31/2021, 1:02 PMTomasz Krakowiak
03/31/2021, 1:03 PMTomasz Krakowiak
03/31/2021, 1:05 PMTomasz Krakowiak
03/31/2021, 1:11 PMarchana 0623
04/12/2021, 6:15 AMTomasz Krakowiak
04/19/2021, 12:11 PM// Define some hooks. Maybe I'll bulk generate those for all tags later.
// Using Element API
fun CTagBuilder<OPTION>.onSelect(callback : (Event) -> Unit) {
attach<HTMLSelectElement> { element -> HTMLSelectElement
//element.onselect = callback
//or
element.addEventListener("onselect", callback)
}
}
// Using TagConsumer API
fun TagConsumer<*>.onSelect(tag : OPTION /** No multiple receivers yet : ( */, callback : (org.w3c.dom.events.Event) -> Unit) {
onTagEvent(tag, "onselect", callback)
}
// This should be global in JS / request scoped on server
val flow: Flow = Flow()
// Define mutable and observable value
val selectedStyle: Property<Style> = flow.Property(defaultStyle)
// Define some content
val styleSelectionBlock: CBlock = {
tag(::SELECT) {
for(style in availableStyles) {
tag(::OPTION) {
onSelect {
flow {
selectedStyle.value = style
}
}
}
}
}
}
fun TagConsumer<*>.styleSelectionBlock2() = {
select {
for(style in availableStyles) {
option {
onSelect(this) {
selectedStyle.value = style
}
}
}
}
}
val styleDemoBlock: CBlock = {
tag(::DIV) {
bind(DIV::classes, selectedStyle.map { setOf(it.className) })
dynamic(selectedStyle) {
"This text is shown with the style \"${it.name}\""
}
}
}
val styleSelectWithPreview : CBlock = {
styleSelectionBlock()
// styleSelectionBlock2() // That works too. kotlinx-html API is supported.
+styleDemoBlock
}
Than
// This is in commonMain, you can render to text on client too.
fun renderOnServer(out : Appendable) {
val context = RootContext(emptyMap())
context.render(styleDemoBlock, out)
}
And
val rootContext by lazy { RootContext(emptyMap())}
fun hydrateOnClient() {
// We already rendered on server. Now we're just binding model/listeners to the DOM
rootContext.hydrate(styleSelectWithPreview, rootElement)
}
// or
fun renderOnClient() {
rootContext.render(styleSelectWithPreview, rootElement)
}
archana 0623
04/30/2021, 6:37 AMarchana 0623
05/26/2021, 12:52 PMmartmists
08/31/2021, 3:44 PMExecution failed for task ':jvmProcessResources'.
> Entry server_style.css is a duplicate but no duplicate handling strategy has been set. Please refer to <https://docs.gradle.org/7.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy> for details.
I also get this while trying to run my project, it says server_style.css is duplicate but it's only in jvmMain/resources and not in jsMain/resources or commonMain/resourcesmartmists
09/15/2022, 11:59 AMSam Gammon
11/10/2022, 3:59 AMSam Gammon
11/10/2022, 3:59 AMSam Gammon
01/01/2023, 2:55 AMnative-image
is supported out of the box.
• 🚀 Trying it out
curl -sSL --tlsv1.2 dl.elide.dev/cli/install.sh | bash -s -
👆 the one liner works on Darwin (amd64/arm64), and Linux (amd64) so far.If you prefer NPX:
npx @elide-dev/elide@alpha shell
K Building Kotlin apps with it
•
Elide can be used as a plain library with a regular Micronaut server, and Ktor support is on the way. There are Maven artifacts in a custom repository which is easy to use during the alpha; you can see a sample here.
• G Gradle plugin
You can easily install the Gradle plugin to build your frontend assets and your Kotlin/JS, and package it into your server binary. It will handle building for SSR and CSR both, so you can easily switch between browser rendering modes. Check it out here. Maven and Bazel support are planned.
• 🖥️ Using the shell
elide shell
drops you into a shell just like Node (see attached screenshot), the difference being the URL
class we're using here is implemented in Kotlin, backed by the road-tested power of Micronaut, KotlinX, Netty, and the Java standard library. It has simply been adapted for use in JavaScript, according to the WhatWG URL Spec.
• js Use Kotlin/JS or regular Node stack
Elide packages and consumes your JS/TS with built-in support for esbuild
, so you can use a standard Node toolchain or the Kotlin/JS stack.
• 💨 Super fast React SSR
Because Elide is basically Kotlin with a super-fast JS runtime attached, it can do JS SSR without leaving the JVM. This can soon be drop-in compatible with many React apps. You can see a live sample here to confirm it is fast and server-rendered. The code for that sample is pasted below to show how simple it is to call back and forth between Kotlin and your React app:
@Page class Index : PageWithProps<YourProps>(YourProps.serializer()) {
// Serve React SSR.
@Get("/") suspend fun indexPage(request: HttpRequest<*>) = ssr(request) { // 1: tell the server we're going to do SSR for this request
head {
title { +"Hello, Elide!" }
stylesheet("/styles/base.css")
stylesheet("/styles/main.css")
script("/scripts/ui.js", defer = true) // <-- 2: serve the CSR bundle so it can hydrate the react SSR response
}
body {
injectSSR(this@Index, request) // <-- 3: execute the JS VM to produce the SSR response, and splice it into the server response
}
}
}
• 🐙 Contributors needed
The future of software is much more polyglot than today's paradigm: developers love to fight about frameworks, but at the end of the day, we're all writing code, and eliminating barriers between languages means easier collaboration and more value for all of us. It shouldn't be a Node vs. The World or a Rust vs. The World argument; we should get to pick and pull the best code we want from anywhere and use it to build our apps, especially from a multi-platform language like Kotlin.
This runtime and framework are designed for that future. *If you agree, join us and make a dent in the universe*; you'll have a chance to be impactful and shape a brave new idea from the ground up.
• 🙏 Thank you
We chose Kotlin because of the fantastic community. 2023 will be a massive year for Kotlin, and we think that betting the farm on it is reasonable and smart. We are super excited about what JetBrains and Kotlin have in store for us with K2, context receivers, value classes... just so much to look forward to.
Cheers and happy new year, Kotlin devs,
K sam
Slack ConversationAnudeep Ananth
04/01/2023, 8:58 AMAlex
11/25/2024, 11:25 AM@JsModule
)?
2. Is this how we could go about building notifications?
a. We’d likely have to include service workers in the HTML files and have build processes (hooked into gradle?), but then the main linked module would provide the bridge functions to communicate with that service worker?
3. A lot of modules these days generate TS definitions. Are there ways to generate/automate the creation of the interfaces based on these definitions?Alex
12/02/2024, 2:04 PMDiego Camilo Peña Ramirez
01/18/2025, 4:28 AMNed Twigg
02/12/2025, 8:02 PM