Fork me on GitHub
#om
<
2016-03-25
>
mhcat16:03:39

hey all, I'm playing with om.next 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?

cmcfarlen18:03:56

@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

mhcat18:03:40

@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!

cmcfarlen18:03:52

@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)

mhcat18:03:27

Ah sweet! I'll do that!

francoiswirion19:03:11

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.

anmonteiro20:03:20

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

anmonteiro20:03:35

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

cmcfarlen20:03:05

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

cmcfarlen20:03:16

I wrote this that does just what you are asking about

francoiswirion20:03:51

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

francoiswirion20:03:35

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

cmcfarlen20:03:40

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