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