I'm fairly experienced with Javascript; but still learning Nim. This weekend, I'm learning how to target js with Nim. Speciifically, I'm targeting a canvas.
In javascript, if I wanted to have the browser client load an image into the canvas, it would be something like:
my_image = new Image();
my_image.src = 'img/blahblah.png';
my_image.onload = function(){
context.drawImage(my_image, 0, 0);
}
The browser would then request the image from the server and draw it to the canvas when finished loading.
And, via Nim, I have access to the canvas and the context. No problem. But I can't for the life of me see how to do the "new Image()" part with Nim. It's probably something simple I'm missing...but after 3 hours my eyes are glazing over... :)
Any help or leads?
Maybe something like:
import karax / kdom
import jsffi
import jsconsole
var image = new(ImageElement)
image.src = "blah.jpg"
image.onload = proc(ev: Event): void =
console.log image
Thanks!
ImageElement is coming from karax/kdom. I'll investigate karax further. kdom appears to be far more complete than dom.
If you don't want to use karax, you can use importcpp to wrap stuff. Here's an example from the jscore module in the stdlib.
Here's the relevant section in the manual (the manual makes it seem like importcpp can only be used with the C++ backend, but it works with C and JS as well).
Yes I think we need to extend the functionality of the JS Standard library.
Karax is a good solution for the right sort of developer but I think it would be quite intimidating to most specialist frontend developers. JSX has more appeal to that group of developers due to its familiar html like syntax.