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