reworked event handling again; added scrollapp example

This commit is contained in:
Andreas Rumpf 2017-04-15 15:50:07 +02:00
commit 686ad23f2f
12 changed files with 273 additions and 225 deletions

View file

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

View file

@ -0,0 +1,24 @@
## Example that shows how to accomplish an "infinitely scrolling" app.
include karaxprelude
import jstrutils, dom
var entries: seq[cstring] = @[]
for i in 1..500:
entries.add(cstring("Entry ") & &i)
proc scrollEvent(ev: Event; n: VNode) =
let d = n.dom
if d != nil and inViewport(d.lastChild):
# "load" more data:
for i in 1..50:
entries.add(cstring("Loaded Entry ") & &i)
proc createDom(): VNode =
result = buildHtml():
tdiv(onscroll=scrollEvent, style="height: 400px; overflow: scroll"):
for x in entries:
tdiv:
text x
setRenderer createDom

View file

@ -0,0 +1 @@
--path: "../../src"