Created
September 18, 2018 15:38
-
-
Save bketelsen/da1e31a7e3c45f83be115ce2bbd1c403 to your computer and use it in GitHub Desktop.
karax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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