Skip to content

Instantly share code, notes, and snippets.

@bketelsen
Created September 18, 2018 15:38
Show Gist options
  • Save bketelsen/da1e31a7e3c45f83be115ce2bbd1c403 to your computer and use it in GitHub Desktop.
Save bketelsen/da1e31a7e3c45f83be115ce2bbd1c403 to your computer and use it in GitHub Desktop.
karax
## This demo shows how you can develop your own stateful components with Karax.
include karax / prelude
import karax / kajax
type
Song = ref object of VComponent
title: kstring
artist: kstring
rating: int
opinion: kstring
spotify_url: kstring
proc render(x: VComponent): VNode =
let self = Song(x)
result = buildHtml(tdiv()):
text self.title
proc cb(httpStatus: int, response: cstring) =
echo response
proc song(): Song =
result = newComponent(Song, render)
ajaxGet("http://localhost:8080/api/content?type=Song&id=1", @[], cb)
proc createDom(): VNode =
result = buildHtml(table):
tr:
td:
song()
setRenderer createDom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment