Hello all,
I'm new here and discovering Nim. It looks like my dream language, so I'm obligated to look it up more. I also discovered that it does frontend JavaScript programming, and this is quite awesome. Because of this, I wondered if there is a web framework offering reactive programming like Svelte does.
Svelte is a web framework that took a different approach to all the Virtual DOM libraries that were around to make a radically more efficient approach. Instead of recomputing a virtual DOM on each operation, and then diffing it against the physical DOM, they change the DOM in place. And it's so much more efficient because Svelte is not a javascript library, but a javascript specific dialect compiler. Svelte knows at compile-time what value changed exactly in which part of the DOM, and is able to just change the single value that changed at the right place. It also offers reactive programming where it recomputes automatically some values when the value they depend on just changed.
I wondered if it was possible to do something like this using Nim meta-programming features.
Doing it the svelte way would require to :
And that's about it, but does Nim allows to hook into this at compile time? We could also imagine a less automatic way to handle things with specific syntax.
Is that inspiring?
It's a nice idea and I heard of Svelte before. I wrote some experiments in Karax to do the same but wrapping every T in a React[T] became tedious, more tedious than the DOM diffing where you can keep your types. With more compiler support the React wrappers can disappear but I think Nim isn't there yet.
The DOM is a stateful, complex beast. If you want to remove the state from it via a language/framework abstraction what you're doing is an "abstraction inversion". The question "which abstraction inversion is the fastest?" doesn't really interest me much anymore. The good solution is to fix the browsers to give us something more low-level than a DOM.
Reactive programming can be quite useful for tons of things. I used it extensively to make a software that would compute tons of dimensions and making drawings of furniture. See for an example: https://github.com/mildred/calcul-meubles/ (in French, sorry).
I'd be glad to still be able to do that even though I might need to wrap all the dependencies of my computation with some special syntax.
As for the browsers, I don't see them providing something log level for the foreseeable future.