-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.hx
53 lines (47 loc) · 1.23 KB
/
Main.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import js.Browser.document;
import js.Browser.window;
import coconut.vdom.Renderer.hxx;
import coconut.data.Model;
import coconut.ui.View;
import coconut.data.*;
import bootstrap.*;
class Main {
static function main() {
coconut.ui.Renderer.mount(
cast document.body.appendChild(document.createDivElement()), hxx('<Root />')
);
}
}
class Root extends View {
@:state var items:List<Item> = null;
function add(_) {
items = items.append(new Item({id: window.prompt("name")}));
}
function remove(id:String) {
items = items.filter(i -> i.id != id);
}
function render() '
<Container>
<Jumbotron>
<h1>Hello, world!</h1>
<p>This is an example of how to use Haxe, Coconut.ui and bootstrap at the same time.</p>
</Jumbotron>
<if ${items.length > 0}>
<p><strong>Total items:</strong> ${items.length}</p>
<else>
<p>Start adding items in your list.</p>
</if>
<ListGroup className="mb-1">
<items>
<for ${i in items}>
<item>${i.id} <Button onclick=${remove(i.id)} variant=${Light} size=${Small} className="float-right">❌</Button></item>
</for>
</items>
</ListGroup>
<Button onclick=${add}>Add item</Button>
</Container>
';
}
class Item implements Model {
@:constant var id:String;
}