Figured it out.  Turns out it had nothing to do with the above calls.  It was 
more a misunderstanding of how local state worked.

This was bad:

(defn weeks-view [calendar]
  (let [weeks (partition 7 calendar)]
    (fn []
      [:tbody.weeks (for [week weeks]
                      [week-view week])])))


This is good:

(defn weeks-view [calendar]
  (let [weeks (partition 7 calendar)]
    [:tbody.weeks (for [week weeks]
                    [week-view week])]))

In the first example, weeks was being trapped into local state so wasn't 
updating properly.

M



On Monday, September 15, 2014 1:35:22 AM UTC-7, Matt Ho wrote:
> I have a toy application written using reagent and cljs-ajax.  The 
> application works with the hard coded state that I initialized with, but now 
> I'm trying to retrieve the state from the database on load.
> 
> Here's what the state looks like originally:
> 
> (def calendar-state (atom {:entries [
>                                       {"date" [2014 8 31] "contents" [{"feed" 
> "sfcf" "content" "sun workout a"}]}
>                                       {"date" [2014 9 1] "contents" [{"feed" 
> "sfcf" "content" "mon workout a"}]}
>                                       {"date" [2014 9 2] "contents" [{"feed" 
> "sfcf" "content" "tue workout a"}]}
>                                       {"date" [2014 9 3] "contents" [{"feed" 
> "sfcf" "content" "wed workout a"}]}
>                                       {"date" [2014 9 4] "contents" [{"feed" 
> "sfcf" "content" "thu workout a"}]}
>                                       {"date" [2014 9 5] "contents" [{"feed" 
> "sfcf" "content" "fri workout a"}]}
>                                       {"date" [2014 9 6] "contents" [{"feed" 
> "sfcf" "content" "sat workout a"}]}
>                                       ]}))
> 
> And here's what I added to the bottom of core.cljs to try and load the data:
> 
> (ajax/GET "/api/calendar"
>   {:handler (fn [entries] (println (str "received => " entries))
>               (println "before")
>               (println @calendar-state)
>               (swap! calendar-state assoc :entries entries)
>               (println "after")
>               (println @calendar-state)
>               (reagent.core/flush))})
> 
> entries returned by the server appears to be correctly formatted:
> 
> [
> {"date" [2014 8 31] "contents" [{"feed" "sfcf" "content" "sun workout a - 
> server"}]}
> {"date" [2014 9 1] "contents" [{"feed" "sfcf" "content" "mon workout a - 
> server"}]}
> {"date" [2014 9 2] "contents" [{"feed" "sfcf" "content" "tue workout a - 
> server"}]}
> {"date" [2014 9 3] "contents" [{"feed" "sfcf" "content" "wed workout a - 
> server"}]}
> {"date" [2014 9 4] "contents" [{"feed" "sfcf" "content" "thu workout a - 
> server"}]}
> {"date" [2014 9 5] "contents" [{"feed" "sfcf" "content" "fri workout a - 
> server"}]}
> {"date" [2014 9 6] "contents" [{"feed" "sfcf" "content" "sat workout a - 
> server"}]}
> ]
> 
> The code doesn't work, but I'm at a loss as to where to go next.
> 
> Any suggestions would be greatly appreciated.
> 
> M

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to