Hello everyone,
As many of you probably already know, Karax is a core Nim web framework. It can be used as a DSL to generate HTML (good for templating on the backend) and to create Single Page Applications in Nim. Karax was mostly written back in 2017, and it powers the frontend of the forum that you are all reading right now!
Karax hasn't seen much love in the past few years, for a few different reasons. The main one is that Araq is busy (turns out he has this other project called Nim 😉), so it hasn't had an official active maintainer. It's also at a state where you could call it mostly feature complete - the main things left to do from a code perspective are fixing bugs and improving performance as needed. Recently, a few folks and I over on the Discord (#web-dev) have been trying to make Karax more usable and approachable for all users. Here's a quick list of some of the things we've accomplished already in the last few weeks
along with a few smaller tweaks to make it more approachable for newer people.
So, why are we making this forum post? We'd love it if more people from the community got involved. Nim's JS backend isn't used nearly as often as the C one, and I'm sure that there are people reading this who tried it or Karax once a few years ago, ran into some weird bug, and then forgot about it. We want to change that. There's plenty of work left to do to make it better.
We're hoping that more eyes on Karax will let it become more mainstream, even among Javascript frameworks. If you've never tried Karax but have used React/Vue/Angular, you'll be surprised by how simple it really is. The core API is very small, all you really need to know are a few events (like onclick, oninput) and HTML (what the tags do). Nim's generous stdlib combined with type checking make for a pleasant experience when compared with vanilla Javascript.
If you want to help, feel free to drop by the #web-dev channel, or start tackling issues. Thanks!
Oh this is so good! Karax could use some love like having its one landing page with tutorials and stuff.
I’ve recently discovered a simpler state management model than the one I’ve described in the old Exploring Karax article, looking forward to write about it too. Alas, the time is always short.
@ajusa Great work, this will certainly help attract more users and get them up and running with Karax.
@moigagoo I'd be interested in hearing more about your new approach to state management. I found your blog post very informative and nicely written, but was left a little unsure as to how best approach state management in Karax, especially with others demonstrating Elm-inspired techniques . Perhaps you could share a snippet for me to explore this further?
Thanks
I would like to mention Svelte specifically. It's a different approach than React/Karax.
But it's well worth to watch talk of Rich Harris creator of Svelte why it created it and how it works.
And maybe go through Svelte Tutorial it's interactive, simple and very well done.
I think there could be ideas in Svelte that could be applied to Nim Reactive UI, given that it has rich macro capabilities.
They say Svelte is faster than React, it's true, but I personally don't care about the UI speed. Modern computers are so insanely powerful that's pretty much impossible to slow it down with UI, unless you do something really wrong or write heavy animations like games.
Svelte is not only faster (which as I mentioned already is not that important) but also simpler and more productive than React. And it feels like that approach could blend well with Nim.
I've recently heard about Knete through : https://github.com/karaxnim/karax/pull/185 which is an experiment of using Nim without using a VDOM: https://github.com/karaxnim/karax/blob/master/experiments/trello/knete.nim
In non-Nim world: https://github.com/davedawkins/Sutil which is also Svelte inspired.
As far as Svelte being simpler and more productive than React, I'd say that depends on person and what they like. But what Svelte does really right is that interactive guide which is amazing.
Lastly, ofcourse I'd like to see Karax evolve into something more intuitive and faster, but with limited resources I'd rather have incremental small changes to Karax than adapting to a totally new framework. Good documentation( https://github.com/karaxnim/karax/pull/199 ) will help Karax currently more than anything IMO.
I haven't used a lot of js (just sprinkled here and there) and i've never used a full fledged js framework in production, but from my somewhat exhaustive (albeit high level) investigations over the years, what i think i want, is sapper/sveltekit (SSR) but in all nim, where the backend, routing etc is in nim compiled to c, and the bare minimum required for the front end features, is nim compiled to js. It would be nice if the compiled js was small too. I saw some indication that nim compiled to js might result in code obesity, but i don't remember what examples i was looking at or anything, so i don't know if that is even true or not.
I will probably want to use plain html or maybe nim's source code filter (i like that and use that on my current site built with nim/prologue) for html, as i'm usually too picky/paranoid for html generation features like in karax.
I haven't tried to use karax already, because i'm not really interested in building SPA's due to SEO, performance concerns, etc. and the svelte propaganda tarnished vdom a little for me. :)
Karax2/Napper/Nimkit :) would have to be well documented (for js/js framework beginners) for me to be able to justify diverting my time to learn something new.
I know this is not really what was asked, but i've been wanting to ask for this for a while so that's what you get. :) However y'all go forward i wish you the best.
what i think i want, is sapper/sveltekit (SSR) but in all nim, where the backend, routing etc is in nim compiled to c, and the bare minimum required for the front end features, is nim compiled to js.
Exactly.
Are there actually any "full stack" single-language and single-codebase solutions out there with considerable "core" support to build (initially) server-rendered (multi-page/route) web applications, and which can work in an offline-first manner (diconnected-operation + resync)? PWA (Progressive Web Apps)?
Best inspirations around which seem to have paved some miles seem meteor (js) / vulcanjs, Phoenix Liveview (Elixir), and https://hyperstack.org .
The latter looks good, however (unfortunately?) is a Rails gem. It's inspired by meteor and uses a rails engine to implement the backend as a rails app. It compiles the ruby code into a js front-end sitting on top of React. So you only code/declare the app in ruby and the gem builds and runs the frontend and backend from it. While the (activerecord) data models are seamlessly delivered and synchronized with the front-end in the background.
Is that something a Nim project is working at?
"core" support to build
read: a much-simplified, productive way to build... (as in the latter example).
Svelte is a great framework. I'm working on a Nim frontend framework combining mutable tracking based on es6 Proxy with direct dom generation.
I'm also experimenting some hacks to make components easier. For example support the implicit children function.
proc buildText*(name: Reactive[cstring]) {.component.} =
build(`div`):
h1: text name
children()
Karax is awesome , but what we really need is documentation not just examples. I have been on my spare time creating javascript apps and converting them to karax ones.
Karax could be a replacement for html, javascript but it lacks docs. I would be willing to "donate" to a karax cause especially for documentation.
@jasonfi
With https://github.com/jfilby/nexus, do you have "isomorphic" in mind?
(One language. One model. One set of tests. The same business logic and domain Models are running on the clients and the server. See: https://hyperstack.org )