nim-webui icon indicating copy to clipboard operation
nim-webui copied to clipboard

New `bindJs` template?

Open neroist opened this issue 1 year ago • 4 comments

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 avatar Jun 23 '23 05:06 neroist

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 avatar Jun 23 '23 05:06 neroist

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

neroist avatar Jun 23 '23 05:06 neroist

Perhaps different names could be used aswell?

neroist avatar Jun 23 '23 05:06 neroist

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.

hassandraga avatar Aug 18 '23 20:08 hassandraga