From f0e2d41fdee293a14b37b92fe1995ece556e6c32 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 17 Apr 2017 09:39:13 +0200 Subject: [PATCH] next step to get stateful components --- experiments/example.nim | 1 - experiments/oldwidgets.nim | 48 ++++++++++++++++ src/components.nim | 111 ++++++++++++++++++++++++------------- src/karax.nim | 15 ++--- 4 files changed, 126 insertions(+), 49 deletions(-) diff --git a/experiments/example.nim b/experiments/example.nim index 78dcaae..61235f8 100644 --- a/experiments/example.nim +++ b/experiments/example.nim @@ -10,7 +10,6 @@ proc carousel*(key: VKey): VNode {.component.} = proc next(ev: Event; n: VNode) = counter = (counter + 1) mod images.len - markDirty key result = buildHtml(tdiv(key=key)): text images[counter] diff --git a/experiments/oldwidgets.nim b/experiments/oldwidgets.nim index 023dc98..c947d7f 100644 --- a/experiments/oldwidgets.nim +++ b/experiments/oldwidgets.nim @@ -201,3 +201,51 @@ proc visibleKeys(e: Node; a, b: var VKey; h, count: var int) = else: for i in 0..= 0 and dirty.contains(&newNode.key): - dirty.del(&newNode.key) - dec dirtyCount + if newNode.key >= 0 and isDirty(newNode.key): + unmarkDirty(newNode.key) let n = vnodeToDom(newNode) if parent == nil: replaceById("ROOT", n) @@ -241,9 +234,9 @@ proc dodraw() = let olddom = document.getElementById("ROOT") updateElement(nil, olddom, newtree, currentTree) #assert same(newtree, document.getElementById("ROOT")) - if dirtyCount > 0: + if someDirty: updateDirtyElements(nil, olddom, newtree) - dirtyCount = 0 + someDirty = false currentTree = newtree # now that it's part of the DOM, give it the focus: if toFocus != nil: