From 497aec21146c03fba19b162ae350af798f063314 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 31 Mar 2017 14:11:42 +0200 Subject: [PATCH] use window.requestAnimationFrame instead of timer based event triggering --- example.nim | 2 +- karax.nim | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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)