Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2016 12:09
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fredyr/8460923 to your computer and use it in GitHub Desktop.
Updated tutorial code for Om 0.1.6. See more at
;; Updated tutorial code for Om 0.1.6, 2014-01-16
;; See comments below for details on the changes.
(def app-state
(atom {:comments [{:author "Pete Hunt" :text "This is a comment."}
{:author "Jordan Walke" :text "This is *another* coment"}]}))
(defn comment [{:keys [author text]} owner]
(dom/div #js {:className "comment"}
(dom/h2 nil author)
(dom/span nil text))))
(defn change-author [cs new-author]
;; The cursors internal path is used, no explicit path needed
(om/update! cs (fn [comments]
(mapv #(assoc % :author new-author) comments))))
(defn comment-list [cs owner]
(dom/div nil
(dom/div #js {:className "commentList"}
;; Helper function build-all builds a vector of components
(om/build-all comment cs))
(dom/button #js {:onClick #(change-author cs "Fredrik")}
"Change authors"))))
(defn comment-box [state owner]
(dom/div #js {:className "commentBox"}
(dom/h1 nil "Comment")
;; Cursors support lookups to yield new cursors, so
;; they can be used directly to pass sub-state,
;; maintaining paths internally
(om/build comment-list (:comments state)))))
(.getElementById js/document "content"))
Copy link

bhoggard commented Dec 2, 2014

I think comment-box needs to appear before app-state in your arguments list starting at line 39.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment