[foo bar] makes a new react component, (foo bar) is just a function call. So in your second example, [make-rows ...] is a component itself and therefore gets rerendered when its subscriptions change - just like every other component that gets rerendered when its data changes. The former is a function call that returns its data, but doesn't by itself get rerun when data changes.
Of course, that only explains why the second version works. I have no idea why the rerender of make-table doesn't call the function each time.. I'm still a bit new to reagent (having used Om for the past year), so am not quite up to speed on all the idiosyncrasies. On Sun, 29 Mar 2015 at 13:38 Colin Yates <colin.ya...@gmail.com> wrote: > Hi all, I have read the docs but might have overlooked something. > > I keep seeing components being updated in response to state changes but I > don't see the latest state in that component. > > For example, in the following: > > (defn- make-rows > [on-click selected-id] > (js/console.log "rows has selected-id: " selected-id) > [:tbody > (for [idx (range 10)] > [:tr > {:class (when (= selected-id idx) "selected") > :on-click #(do (on-click idx) nil)} > [:td "Some state"]])]) > > (defn make-table [] > (let [selected-id (subscribe [:search/selected-journey-id])] > (fn [] > (js/console.log "make-table has selected-id: " @selected-id) > [table/table {:headers [{:class :ignore-me :text "whatever"}] > :rows (make-rows #(dispatch > [:search/select-journey-id %]) > @selected-id)}]))) > > when I call [make-table] then I can see both make-table and make-rows > being called with the new selected-id, but table/table never gets the new > selected-id, it is always called with the old selected-id. It is as if the > invocation to (rows) is cached. > > Changing make-table to use [make-rows] makes the problem worse as only > make-tables is called in response to the selected-id changing. > > The only way I can get this to work is to make-rows itself subscribe to > the selected-id: > > (defn- make-rows > [on-click] > (let [selected-id (subscribe [:search/selected-journey-id])] > (fn [] > (js/console.log "rows has selected-id: " @selected-id) > [:tbody > (for [idx (range 10)] > [:tr > {:class (when (= @selected-id idx) "selected") > :on-click #(do (on-click idx) nil)} > [:td "Some state"]])]))) > > (defn make-table [] > [table/table {:headers [{:class :ignore-me :text "whatever"}] > :rows [make-rows #(dispatch [:search/select-journey-id > %])]}]) > > Can somebody please explain why calling an fn with a @subscription is the > wrong thing to do. > > Thanks for reading this far ;). > > > -- > 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. > -- 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.