sane markDirty() mechanism for components

This commit is contained in:
Andreas Rumpf 2017-06-21 17:20:31 +02:00
commit d9648be60c
6 changed files with 41 additions and 27 deletions

15
experiments/carousel.html Normal file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Carousel app</title>
</head>
<body id="body">
<div id="ROOT" />
<script type="text/javascript" src="nimcache/carousel.js"></script>
</body>
</html>

View file

@ -1,3 +1,4 @@
## This demo shows how you can develop your own stateful components with Karax.
import vdom, vstyles, karax, karaxdsl, jdict, jstrutils, kdom
@ -7,7 +8,6 @@ type
cntdown, myid: int
timer: TimeOut
list: seq[cstring]
change: bool
const ticksUntilChange = 5
@ -24,11 +24,10 @@ proc render(x: VComponent): VNode =
self.cntdown = ticksUntilChange
else:
self.timer = setTimeout(docount, 30)
self.change = true
markDirty(self)
redraw()
proc onclick(ev: Event; n: VNode) =
self.change = false
if self.timer != nil:
clearTimeout(self.timer)
self.timer = setTimeout(docount, 30)
@ -51,12 +50,8 @@ proc render(x: VComponent): VNode =
var gid: int
proc changed(c: VComponent): bool =
let x = Carousel(c)
result = x.change
proc carousel(): Carousel =
result = newComponent(Carousel, render, changed)
result = newComponent(Carousel, render)
result.list = images
result.cntdown = ticksUntilChange
result.myid = gid

View file

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Todo app</title>
</head>
<body id="body">
<div id="ROOT" />
<script type="text/javascript" src="nimcache/example.js"></script>
</body>
</html>