Merge branch 'master' into master
This commit is contained in:
commit
387c8b79fb
6 changed files with 43 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
||||||
nimcache/
|
nimcache/
|
||||||
/tests/tester
|
/tests/tester
|
||||||
/tools/karun
|
/tools/karun
|
||||||
*.code-workspace
|
*.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
|
WebSocket* {.importc.} = ref object
|
||||||
onmessage*: proc (e: MessageEvent)
|
onmessage*: proc (e: MessageEvent)
|
||||||
|
onopen*: proc (e: MessageEvent)
|
||||||
|
|
||||||
proc newWebSocket*(url, key: cstring): WebSocket
|
proc newWebSocket*(url, key: cstring): WebSocket
|
||||||
{.importcpp: "new WebSocket(@)".}
|
{.importcpp: "new WebSocket(@)".}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import karax
|
import karax
|
||||||
|
|
||||||
proc ajax(meth, url: cstring; headers: openarray[(cstring, cstring)];
|
proc ajax*(meth, url: cstring; headers: openarray[(cstring, cstring)];
|
||||||
data: cstring;
|
data: cstring;
|
||||||
cont: proc (httpStatus: int; response: cstring);
|
cont: proc (httpStatus: int; response: cstring);
|
||||||
kxi: KaraxInstance = kxi,
|
kxi: KaraxInstance = kxi,
|
||||||
|
|
@ -61,5 +61,17 @@ proc ajaxGet*(url: cstring; headers: openarray[(cstring, cstring)];
|
||||||
kxi: KaraxInstance = kxi) =
|
kxi: KaraxInstance = kxi) =
|
||||||
ajax("GET", url, headers, nil, cont, 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 toJson*[T](data: T): cstring {.importc: "JSON.stringify".}
|
||||||
proc fromJson*[T](blob: cstring): T {.importc: "JSON.parse".}
|
proc fromJson*[T](blob: cstring): T {.importc: "JSON.parse".}
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,7 @@ proc updateStyles(newNode, oldNode: VNode) =
|
||||||
if oldNode.dom != nil:
|
if oldNode.dom != nil:
|
||||||
if newNode.style != nil: applyStyle(oldNode.dom, newNode.style)
|
if newNode.style != nil: applyStyle(oldNode.dom, newNode.style)
|
||||||
else: oldNode.dom.style = Style()
|
else: oldNode.dom.style = Style()
|
||||||
|
oldNode.dom.class = newNode.class
|
||||||
oldNode.style = newNode.style
|
oldNode.style = newNode.style
|
||||||
oldNode.class = newNode.class
|
oldNode.class = newNode.class
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue