There's WebView binding for Nim NimView, but it still use JS. Why it still use JS?
I'm confused how it works, it says:
Use Nim, Python, C or C++ for your back-end > Use any HTML/CSS/JS based UI you want - Svelte, Vue, React, plain JS etc..
Well, if I'm going to use React/Svelte for my Desktop App UI, why would I need Nim?
I get why you may use two languages for Web App, because for Multi User Web App the Server Part is huge and Svelte UI + Nim Server with code split like 50% in JS and 50% in Nim (or maybe even much more), using two languages looks reasonable.
But for Desktop App, business logic usually small, so do you really want to have Svelte UI + Nim Business Logic, with code like 90% in JS and 10% in Nim? Really? You want to bring another language just so you will be able to write those 5-10% of codebase in Nim?
Second question: I'm wondering why do we need JS at all?
We don't need JS, what we need is 1) CSS render 2) minimal DOM API and 3) minimal events. All those provided by WebKit.
Isn't it possible to just bypass the JS runtime and modify DOM and register events directly from Nim? (as C handlers, via Nim C interface)?
The DOM API and Event Model don't need to adhere to full JS spec, 90% of it could be ignored, only the minimal basics needed, like add/remove/modify DOM nodes and listen to click and keypress events.
So the UI loop may look like:
Is there any such UI kit in Nim?
Thanks, yes, I guess there's no such frameworks.
They say, Brendan Eich, creator of JavaScript, implemented JavaScript and attached it to InternetExplorer engine in something like 3 days or so, maybe a bit more. It's strange that since then, for 27 years, nobody was able to repeat that with other language.
Why do you need "back-end" in Desktop App?
Right... Nowadays, most UI software usually doesn't perform any actual task anymore. Most have just some CLI executable and the UI just calls this executable via cmd/shell. But - in case that you have some nice nim library and want to have some UI for it, you could just trigger the lib in the backend. If you don't need any actual backend, you might better use something like tauri (rust), which does something similar as nimview but is much more mature.
I'm wondering can we do it without any JS?
The problem is probably form / action logic. Webview doesn't has routes and therefore, you would need some kind of HTTP server that handles all your routes. But having some local HTTP server would also have some negative security implications. There had been some CSRF attacks on Microsoft applications in the past, that were using local HTTP servers.
Even if you don't need reactivity of JS and just want to have HTML, you would probably still need to display some data in a form or have some feedback. For this, you would need some logic and for this, you would need some language like JS. You probably still could use some template lib (mustache?) in nim to fill HTML and then send this to Webview to be displayed. But most modern approaches use JS frameworks for this as these are widely tested, widely used and are usually very flexible.
Also, most good UI stuff is made with reactive JS components. The best examples for this are googe maps or VS code. You wouldn't be able to do these without Javascript. Or at least those wouldn't be as good as they are without any JS.
Maybe I miss something. Why in the WebView, the JS engine, couldn't be ripped off, and the Nim engine being put in instead? So you have all the same HTML/DOM/Events stuff, but write code in Nim instead of JS?
The say, the story of how JS was created. Microsoft came to Brendan Eich and said they want do add some language to Internet Explorer, and that language should look similar to Java. And Brendan Eich invented JS and plug it in Internet Explorer in something like 10 days or so (maybe more, but that's what they say).
It's just strange that since then, for 27 years, no one tried to replace JS with something else :)