Merge branch 'master' into master
This commit is contained in:
commit
387c8b79fb
6 changed files with 43 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@ nimcache/
|
|||
/tests/tester
|
||||
/tools/karun
|
||||
*.code-workspace
|
||||
*.exe
|
||||
|
|
|
|||
1
experiments/config.nims
Normal file
1
experiments/config.nims
Normal file
|
|
@ -0,0 +1 @@
|
|||
--path: "../src"
|
||||
25
experiments/scrollapp_simple.nim
Normal file
25
experiments/scrollapp_simple.nim
Normal 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
|
||||
|
|
@ -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(@)".}
|
||||
|
|
|
|||
|
|
@ -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".}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue