Do not shadow core function; implement obj->clj

This commit is contained in:
Jeremy Dormitzer 2018-01-18 09:41:21 -05:00
parent 42cca5be6f
commit 2a66aa03ef
No known key found for this signature in database
GPG Key ID: 04F17C0F5A32C320

View File

@ -64,7 +64,7 @@
[]
{:items ()})
(defn update
(defn update-state
"Given a message and the old state, returns the new state"
[msg state]
(case (:type msg)
@ -89,12 +89,21 @@
"Runs the model-update-view loop"
[state]
(let [dispatch-message (fn [msg]
(let [new-state (update msg state)]
(let [new-state (update-state msg state)]
(main new-state)))]
(render (view dispatch-message state))))
(main (model))
(defn obj->clj [obj]
(into {} (for [k (.keys js/Object obj)]
[(keyword k)
(let [v (aget obj k)]
(cond
(object? v) (obj->clj v)
(.isArray js/Array v) (map obj->clj (array-seq v))
:default (js->clj v)))])))
(go (-> js/browser
(.-runtime)
(.sendMessage (clj->js {:type "fetchItems"}))
@ -102,8 +111,8 @@
(<!)
(array-seq)
((fn [items] (filter #(not (nil? %)) items)))
(#(update {:type :items
:items %} (model)))
(#(update-state {:type :items
:items (map obj->clj %)} (model)))
(main)))
(defn handle-close-button [e]