Advertisement
Guest User

Untitled

a guest
Oct 18th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns ^:figwheel-always om-tut.core
  2.     (:require[om.core :as om :include-macros true]
  3.               [om.dom :as dom :include-macros true]))
  4.  
  5. (enable-console-print!)
  6.  
  7. (println "Edits to this text should show up in your developer console!")
  8.  
  9. ;; define your app data so that it doesn't get over-written on reload
  10.  
  11. (defonce app-state (atom
  12.                     {:contacts
  13.                      [{:first "Ben" :last "Bitdiddle" :email "benb@mit.edu"}
  14.                       {:first "Alyssa" :middle-initial "P" :last "Hacker" :email "aphacker@mit.edu"}
  15.                       {:first "Eva" :middle "Lu" :last "Ator" :email "eval@mit.edu"}
  16.                       {:first "Louis" :last "Reasoner" :email "prolog@mit.edu"}
  17.                       {:first "Cy" :middle-initial "D" :last "Effect" :email "bugs@mit.edu"}
  18.                       {:first "Lem" :middle-initial "E" :last "Tweakit" :email "morebugs@mit.edu"}]}))
  19.  
  20. (defn middle-name [{:keys [middle middle-initial]}]
  21.   (cond
  22.     middle (str " " middle)
  23.     middle-initial (str " " middle-initial ".")))
  24.  
  25. (defn display-name [{:keys [fist last] :as contact}]
  26.   (str last ", " first (middle-name contact)))
  27.  
  28. (defn contact-view [contact owner]
  29.   (reify
  30.       om/IRender
  31.     (render [this]
  32.       (dom/li nil (display-name contact)))))
  33.  
  34. (defn contacts-view [data owner]
  35.   (reify
  36.       om/IRender
  37.     (render [this]
  38.       (dom/div nil
  39.                (dom/h2 nil "Contact list")
  40.                (apply dom/ul nil
  41.                       (om/build-all contact-view (:contacts data)))))))
  42.  
  43. (om/root contacts-view app-state
  44.   {:target (. js/document (getElementById "contacts"))})
  45.  
  46. (defn on-js-reload []
  47.   ;; optionally touch your app-state to force rerendering depending on
  48.   ;; your application
  49.   ;; (swap! app-state update-in [:__figwheel_counter] inc)
  50. )
  51.  
  52. ;;; browser output
  53.  
  54. Contact list
  55.  
  56. Bitdiddle, function cljs$core$first(coll){ if((coll == null)){ return null; } else { if(((!((coll == null)))?((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || (coll.cljs$core$ISeq$))?true:false):false)){ return coll.cljs$core$ISeq$_first$arity$1(null); } else { var s = cljs.core.seq(coll); if((s == null)){ return null; } else { return cljs.core._first(s); } } } }
  57. Hacker, function cljs$core$first(coll){ if((coll == null)){ return null; } else { if(((!((coll == null)))?((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || (coll.cljs$core$ISeq$))?true:false):false)){ return coll.cljs$core$ISeq$_first$arity$1(null); } else { var s = cljs.core.seq(coll); if((s == null)){ return null; } else { return cljs.core._first(s); } } } } P.
  58. Ator, function cljs$core$first(coll){ if((coll == null)){ return null; } else { if(((!((coll == null)))?((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || (coll.cljs$core$ISeq$))?true:false):false)){ return coll.cljs$core$ISeq$_first$arity$1(null); } else { var s = cljs.core.seq(coll); if((s == null)){ return null; } else { return cljs.core._first(s); } } } } Lu
  59. Reasoner, function cljs$core$first(coll){ if((coll == null)){ return null; } else { if(((!((coll == null)))?((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || (coll.cljs$core$ISeq$))?true:false):false)){ return coll.cljs$core$ISeq$_first$arity$1(null); } else { var s = cljs.core.seq(coll); if((s == null)){ return null; } else { return cljs.core._first(s); } } } }
  60. Effect, function cljs$core$first(coll){ if((coll == null)){ return null; } else { if(((!((coll == null)))?((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || (coll.cljs$core$ISeq$))?true:false):false)){ return coll.cljs$core$ISeq$_first$arity$1(null); } else { var s = cljs.core.seq(coll); if((s == null)){ return null; } else { return cljs.core._first(s); } } } } D.
  61. Tweakit, function cljs$core$first(coll){ if((coll == null)){ return null; } else { if(((!((coll == null)))?((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || (coll.cljs$core$ISeq$))?true:false):false)){ return coll.cljs$core$ISeq$_first$arity$1(null); } else { var s = cljs.core.seq(coll); if((s == null)){ return null; } else { return cljs.core._first(s); } } } } E.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement