-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo-app.lisp
47 lines (43 loc) · 1.63 KB
/
demo-app.lisp
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
(#j:console:log "Loading demo-app.lisp...")
(defun remove-at-index (idx l)
(loop for i from 0 for item in l when (not (= i idx)) collect item))
(defcomponent (btn 0) (set-state state props)
(let ((handler (lambda (event)
(funcall set-state (1+ state)))))
(render
"button"
(object "onClick" handler)
"Hello, world: "
state)))
(defcomponent (todo-list '("" ("Some Items" "Some Items"))) (set-state state props &rest whatever)
(destructuring-bind
(temp items)
state
(let ((onchange (lambda (evt) (funcall set-state (list (getobj "value" (getobj "target" evt)) items))))
(add (lambda (event)
(#j:window:preventDefault event)
(funcall set-state (list "" (cons temp items)))))
(make-deleter (lambda (i)
(lambda (evt)
(funcall set-state (list temp (remove-at-index i items)))))))
(render "div" #()
("ul"
#()
(apply #'vector
(loop for item in items
for i from 0
collect (render
"li"
(object "key" i)
("button" (object "onClick" (funcall make-deleter i) "style" (object "marginRight" "10px")) "x")
item))))
("form"
(object "onSubmit" add)
("input" (object "value" temp "onChange" onchange))
("button" (object "onClick" add) "Add item"))))))
(mount "root"
(render "div" #()
("h1" #() "Hello, World!")
((btn))
("h2" #() "Todo list:")
((todo-list))))