https://maciej.codes/2023-03-23-kobold.html Introducing Kobold Posted on March 23, 2023 Kobold logo Kobold is a crate for creating declarative web UI. The TodoMVC implemented in Kobold weighs about 30kb when gzipped over the wire, out of which the gzipped Wasm blob is under 20kb. There are no tricks there. I haven't replaced the default allocator, nor have I minified the JavaScript (although I probably should). The goal I have set for myself was creating something that works and feels like a yet another JSX-esque library akin to React or Yew, but without the full performance overhead of Virtual DOM. All of it in Rust, of course. The documentation combined with the examples should give you some insight into building things. What I would like to do here instead is lay down some context, explain how I think about this problem space and how Kobold actually works. Zero-Cost Static HTML On the surface Kobold works exactly like a Virtual-DOM-based library. There are no extra containers to wrap your data in and it does indeed perform the dreaded diffing, however the only thing that ever gets diffed is your data. I first started experimenting in December of 2019 with a procedural macro that would eventually become the view! macro in Kobold. I didn't think about components, or data states, event handling, or even rendering lists. All I wanted is something that looked like JSX, but instead of producing Virtual DOM it would produce pre-compiled JavaScript code to manage all the stuff in the DOM that never changes. Ignoring components for now, the absolute simplest piece of code we could do with Kobold would look something like this: fn hello() -> impl View { view! {
"Counter is at "{ count }
} }) This creates a stateful view. In this case the state is just a simple i32 integer. The count argument passed into the closure is of type & Hook