From 2a66aa03ef8387a86c30afac41ba40f243d4bcbf Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 18 Jan 2018 09:41:21 -0500 Subject: [PATCH] Do not shadow core function; implement obj->clj --- src/looped_in/sidebar.cljs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/looped_in/sidebar.cljs b/src/looped_in/sidebar.cljs index 2ee7da1..d09d539 100644 --- a/src/looped_in/sidebar.cljs +++ b/src/looped_in/sidebar.cljs @@ -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 @@ (clj %)} (model))) (main))) (defn handle-close-button [e]