From a01462673d89559acf572d30edf1b86f5747a5cc Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 1 Sep 2011 12:29:21 -0400 Subject: [PATCH] in a position to need xexps --- web-world/examples/todo/todo.rkt | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/web-world/examples/todo/todo.rkt b/web-world/examples/todo/todo.rkt index 67fce56..8caaab6 100644 --- a/web-world/examples/todo/todo.rkt +++ b/web-world/examples/todo/todo.rkt @@ -6,15 +6,37 @@ (define-resource index.html) +(define-struct item (id content)) + +(define (new-item content) + (make-item (symbol->string (gensym 'item)) + content)) + (define (on-add world view) (local [(define text (view-form-value (view-focus view "#next-item")))] - (cons text world))) + (cons (new-item text) world))) -(define (to-draw world view) - ) + +(define (draw world view) + (foldl add-item-to-view + view + world)) + + +(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. + `(li (@ (id ,(item-id item))) + (item-content item)))])) + + (define the-view @@ -24,4 +46,5 @@ (big-bang '() - (initial-view the-view)) \ No newline at end of file + (initial-view the-view) + (to-draw draw)) \ No newline at end of file