Last active
May 6, 2016 19:32
-
-
Save micha/3fdbaa46cb5fe363f887ef39081618ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(page "index.html") | |
(defc db (sorted-map)) | |
(defn append-item! [txt] (swap! db assoc (gensym) txt)) | |
(defn edit-item! [id txt] (swap! db assoc id txt)) | |
(defn delete-item! [id] (swap! db dissoc id)) | |
(cell= (println (pr-str db))) | |
(defmethod do! :value2 | |
[elem k [v]] | |
(let [$e (js/jQuery elem)] | |
(when-not (.data $e "hoplon-value") | |
(when (cell? v) | |
(.data $e "hoplon-value" true) | |
(.on $e "keyup" #(with-timeout 0 (.val $e @v))) | |
(do-watch v #(.val $e %2)))))) | |
(html | |
(body | |
(h3 "Item database") | |
(textarea :cols "80" :rows "10" :disabled "true" (cell= (pr-str db))) | |
(h3 "Add an item") | |
(let [new-item (cell "")] | |
(div | |
(form | |
:submit #(dosync | |
(append-item! @new-item) | |
(reset! new-item "")) | |
(input | |
:value new-item | |
:type "text" | |
:keyup #(reset! new-item @%)) | |
(button "Add")))) | |
(h3 "See and edit items") | |
(ol | |
(loop-tpl | |
:bindings [[id txt] db] | |
(li | |
(span | |
(input | |
:value2 [txt] | |
:keyup #(if (empty? @%) | |
(delete-item! @id) | |
(edit-item! @id @%))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment