I guess my generic use-case is that I have a component which calls another 
component and needs to pass in some config to that component which comes from a 
subscription which is local to the component.

On Sunday, 29 March 2015 14:24:43 UTC+1, Colin Yates  wrote:
> Hi Daniel, I am in the same position :).
> 
> re: function call; I guess I had assumed that make-table would be
> re-rendered and thus make-table re-invoked, but I guess not. As to the
> first, yeah, it's a puzzler.
> 
> On 29 March 2015 at 14:03, Daniel Kersten <[email protected]> wrote:
> > [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 <[email protected]> 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 [email protected].
> >> To post to this group, send email to [email protected].
> >> 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 [email protected].
> > To post to this group, send email to [email protected].
> > 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to