Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns om-tut.core
- (:require [om.core :as om :include-macros true]
- [om.dom :as dom :include-macros true]))
- (enable-console-print!)
- (println "This text is printed from src/om-tut/core.cljs. Go AAAhead and edit it and see reloading in action.")
- ;; define your app data so that it doesn't get over-written on reload
- (defonce app-state
- (atom
- {:contacts
- [{:first "Ben" :last "Bitdiddle" :email "benb@mit.edu"}
- {:first "Alyssa" :middle-initial "P" :last "Hacker" :email "aphacker@mit.edu"}
- {:first "Eva" :middle "Lu" :last "Ator" :email "eval@mit.edu"}
- {:first "Louis" :last "Reasoner" :email "prolog@mit.edu"}
- {:first "Cy" :middle-initial "D" :last "Effect" :email "bugs@mit.edu"}
- {:first "Lem" :middle-initial "E" :last "Tweakit" :email "morebugs@mit.edu"}]}))
- (defn middle-name [{:keys [middle middle-initial]}]
- (cond
- middle (str " " middle)
- middle-initial (str " " middle-initial ".")))
- (defn display-name [{:keys [first last] :as contact}]
- (str last ", " first (middle-name contact)))
- (defn contact-view [contact owner]
- (reify
- om/IRender
- (render [this]
- (dom/li nil (display-name contact)))))
- (defn contacts-view [data owner]
- (reify
- om/IRender
- (render [this]
- (dom/div nil
- (dom/h2 nil "Contact list")
- (apply dom/ul nil
- (om/build-all contact-view (:contacts data)))))))
- (om/root contacts-view app-state
- {:target (. js/document (getElementsById "contacts"))})
- (defn on-js-reload []
- ;; optionally touch your app-state to force rerendering depending on
- ;; your application
- ;; (swap! app-state update-in [:__figwheel_counter] inc)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement