diff --git a/example.nim b/example.nim index 6a03fac..c7d922b 100644 --- a/example.nim +++ b/example.nim @@ -86,4 +86,4 @@ setRenderer createDom proc onload(session: cstring) {.exportc.} = for i in 0..10_000: entries.add("Entry " & $i) - redraw() + init() diff --git a/karax.nim b/karax.nim index c050597..efb9f43 100644 --- a/karax.nim +++ b/karax.nim @@ -147,15 +147,22 @@ proc dodraw() = if toFocus != nil: toFocus.focus() +proc reqFrame(callback: proc()) {.importc: "window.requestAnimationFrame".} + proc redraw*() = # we buffer redraw requests: - when true: + when false: if drawTimeout != nil: clearTimeout(drawTimeout) drawTimeout = setTimeout(dodraw, 30) + elif true: + reqFrame(dodraw) else: dodraw() +proc init*() = + reqFrame(dodraw) + #proc prepend*(parent, kid: Element) = # parent.insertBefore(kid, parent.firstChild) # prependChild(parent, kid)