webui-dev / nim-webui

Use any web browser as GUI, with Nim in the backend and HTML5 in the frontend.
https://webui.me
MIT License
130 stars 9 forks source link

New `bindJs` template? #23

Open neroist opened 1 year ago

neroist commented 1 year ago

It would be cool to have some kind of "bindJS" template, where it takes the given Nim code and transpiles it to JS to then binds the generated JS code to the id.

neroist commented 1 year ago

Maybe a macro instead?

Proposed process:

  1. recieve code -> save to temp nim file -> transpile to JS function, output file to root folder
  2. transform original call to bind call, with the function body calling the generated JS function with run
  3. finally, link js file to html code

Should collect all JS code in the program then output all of it to the nim file.

neroist commented 1 year ago

Maybe also an additional defineJsFunction macro? Accepts function name and body and just simply transpiles code to JS and links to window

neroist commented 1 year ago

Perhaps different names could be used aswell?

hassandraga commented 1 year ago

I want to mention that webui_bind() works only before the window is shown. That's because we make webui.js listen only to the binded elements to avoid non-needed communication between UI and the backend.

But we can easily add new API to webui.js to add new elements in runtime. Please keep this open.