Fork me on GitHub

hey all, I'm playing with and trying to have a component handle its own deletion - my delete mutation dissocs it by id from the /by-id key in the normalized state, but it doesn't re-render until another event is handled (then the component disappears). I've been trying to figure out how to have the containing component notified (which, I've seen suggestions that's how to handle this), but I don't have a local ref to the containing component. Is that the right approach? and is there a way to get a reference to the enclosing component ident?


@j0ni: might have the parent do the delete and pass down a computed fn to the child that can be called when the delete event happens


@cmcfarlen: thanks I ended up passing a closure in with props which sounds like the same solution. Tho "computed" sounds like it refers to a better way? I'll read tfm. Thanks again!


@j0ni: yes, computed is for passing extra stuff with props, but without changing props. (om/computed props {:delete (fn ...)}) and then inside the child (om/get-computed props :delete)


Ah sweet! I'll do that!


A question about the om/computed and om/get-computed mechanism: if you want to pass down to grandchildren or deeper, at each level you need to take apart the computed bundle and reassemble it for further down-passing, right? There is no mechanism for having scope that is global to all descendants of a certain component? I agree that the latter would be a less functional way, but the computed / get-computed dance in intermediate components feels tedious.


@francoiswirion: yes, you need to take them apart for further passing down


you can always write a function that does this for you so that it's not so tedious simple_smile


(defn forward-computed-factory
  [this f]
  (let [c (om/get-computed this)]
    (fn [props & [computes]]
      (f (om/computed props
                      (cond-> c
                        (merge computes)))))))


I wrote this that does just what you are asking about


@anmonteiro: Ah thanks, just wanted to make sure I wasn't missing something.


@cmcfarlen: Ask, and you shall receive. simple_smile Thanks!


Usage: (let [f (forward-computed-factory this (om/factory OtherComponent))] (f props {:other-computed ...}))