Skip to content
Permalink
Browse files

Set up read function, parser, reconciler. Get data from server & swap…

… it into app state
  • Loading branch information
jraines committed Nov 3, 2015
1 parent 39be499 commit f44d51670c992fbfc909b324e5541e4b68e991da
Showing with 34 additions and 5 deletions.
  1. +5 −0 README.md
  2. +28 −4 src/simoutfit/core.cljs
  3. +1 −1 src/simoutfit/server.clj
@@ -61,3 +61,8 @@ Transit is a data format that plays extra nicely with clojure data structures.
In this commit, we set up our server, routes, and add a few helper functions
for writing & reading transit data. Finally we use a library from Google Closure to make an ajax request to fetch some data.


### Om

The next few commits follow the Om quickstart guide

@@ -7,14 +7,36 @@

(enable-console-print!)

(defonce app-state (atom {:message "Hello Om"}))

(defmulti read (fn [env key params] key))

(defmethod read :default
[{:keys [state] :as env} key params]
(let [st @state]
(if-let [[_ value] (find st key)]
{:value value}
{:value :not-found})))


(defui HelloWorld
static om/IQuery
(query [this]
'[:message])
Object
(render [this]
(dom/div nil (get (om/props this) :message))))

(def hello (om/factory HelloWorld))

(js/ReactDOM.render (hello {:message "Hello Om"}) (gdom/getElement "app"))
(def reconciler
(om/reconciler
{:state app-state
:parser (om/parser {:read read})}))

(om/add-root! reconciler
HelloWorld (gdom/getElement "app"))




(def r (t/reader :json))
@@ -27,8 +49,10 @@

(get-data "/data"
(fn [res]
(println res)
(println (t/read r res))))
(let [resp (t/read r res)
_ (println resp)
msg (:message resp)]
(swap! app-state assoc :message msg))))


(defn on-js-reload []
@@ -20,7 +20,7 @@

(defroutes app
(route/resources "/")
(GET "/data" [] (transit-response {"message" "Hello World"})))
(GET "/data" [] (transit-response {:message "Hello from server"})))

(defn -main []
(run-server app {:port 5000}))

0 comments on commit f44d516

Please sign in to comment.