Merge branch 'master' into master

This commit is contained in:
Thomas Johnson 2017-11-30 11:52:18 -08:00 • committed by GitHub
commit 387c8b79fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 2 deletions

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
nimcache/
/tests/tester
/tools/karun
*.code-workspace
*.code-workspace
*.exe

1
experiments/config.nims Normal file
View file

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

View file

@ -0,0 +1,25 @@
## Example that shows how to accomplish an "infinitely scrolling" app.
include karax / prelude
import karax / [kdom, vstyles]
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=style(
(StyleAttr.height, cstring"400px"), (StyleAttr.overflow, cstring"scroll"))):
for x in entries:
tdiv:
text x
setRenderer createDom

View file

@ -6,6 +6,7 @@ type
WebSocket* {.importc.} = ref object
onmessage*: proc (e: MessageEvent)
onopen*: proc (e: MessageEvent)
proc newWebSocket*(url, key: cstring): WebSocket
{.importcpp: "new WebSocket(@)".}

View file

@ -5,7 +5,7 @@
import karax
proc ajax(meth, url: cstring; headers: openarray[(cstring, cstring)];
proc ajax*(meth, url: cstring; headers: openarray[(cstring, cstring)];
data: cstring;
cont: proc (httpStatus: int; response: cstring);
kxi: KaraxInstance = kxi,
@ -61,5 +61,17 @@ proc ajaxGet*(url: cstring; headers: openarray[(cstring, cstring)];
kxi: KaraxInstance = kxi) =
ajax("GET", url, headers, nil, cont, kxi)
proc ajaxPut*(url: cstring; headers: openarray[(cstring, cstring)];
data: cstring;
cont: proc (httpStatus: int, response: cstring);
kxi: KaraxInstance = kxi) =
ajax("PUT", url, headers, data, cont, kxi)
proc ajaxDelete*(url: cstring; headers: openarray[(cstring, cstring)];
cont: proc (httpStatus: int, response: cstring);
kxi: KaraxInstance = kxi) =
ajax("DELETE", url, headers, nil, cont, kxi)
proc toJson*[T](data: T): cstring {.importc: "JSON.stringify".}
proc fromJson*[T](blob: cstring): T {.importc: "JSON.parse".}

View file

@ -260,6 +260,7 @@ proc updateStyles(newNode, oldNode: VNode) =
if oldNode.dom != nil:
if newNode.style != nil: applyStyle(oldNode.dom, newNode.style)
else: oldNode.dom.style = Style()
oldNode.dom.class = newNode.class
oldNode.style = newNode.style
oldNode.class = newNode.class