dynamic item insertion.
This commit is contained in:
parent
9dab7ba329
commit
a96b8a4538
|
@ -8,35 +8,37 @@
|
|||
|
||||
(define-struct item (id content))
|
||||
|
||||
|
||||
;; new-item: string -> item
|
||||
(define (new-item content)
|
||||
(make-item (symbol->string (gensym 'item))
|
||||
content))
|
||||
|
||||
|
||||
|
||||
;; world view -> world
|
||||
(define (on-add world view)
|
||||
(local [(define text (view-form-value (view-focus view "#next-item")))]
|
||||
(cons (new-item text) world)))
|
||||
|
||||
|
||||
|
||||
;; world view -> view
|
||||
(define (draw world view)
|
||||
(foldl add-item-to-view
|
||||
view
|
||||
world))
|
||||
|
||||
|
||||
|
||||
;; add-item-to-view: item view -> view
|
||||
(define (add-item-to-view item view)
|
||||
(cond
|
||||
[(view-focus? view (format "#~a" (item-id item)))
|
||||
view]
|
||||
[else
|
||||
(view-append-child (view-focus view "#items")
|
||||
;; FIXME: I want this to add a DOM to this.
|
||||
(xexp->dom `(li (@ (id ,(item-id item)))
|
||||
,(item-content item))))]))
|
||||
|
||||
|
||||
|
||||
(define the-view
|
||||
(view-bind (view-focus (->view index.html) "#add-button")
|
||||
|
@ -44,6 +46,7 @@
|
|||
on-add))
|
||||
|
||||
|
||||
(big-bang '()
|
||||
(big-bang (list (new-item "milk")
|
||||
(new-item "eggs"))
|
||||
(initial-view the-view)
|
||||
(to-draw draw))
|
Loading…
Reference in New Issue
Block a user