om

Please ask the channel first, not @dnolen directly!
ag 2017-03-10T04:34:28.505714Z

has anyone ever used ref? can someone show me a piece of snippet where the component ref is being set and then used?

anmonteiro 2017-03-10T04:50:49.568457Z

@ag

(defui Child
  Object
  (render [this]
    (dom/div nil "hello from child")))

(defui Parent
  Object
  (render [this]
    (dom/div nil
      ((om/factory Child) {:ref "child-component"}))))

ag 2017-03-10T04:52:24.574876Z

oh, ok. how about attaching it from inside the components itself and then accessing within it too?

ag 2017-03-10T04:54:25.582755Z

I dunno if Iโ€™m trying to use the right tool though. So basically I need to access one of the dom elements from within a component. e.g. you have two input fields and then based on whatโ€™s typed in one you have to focus on the second field

ag 2017-03-10T05:03:09.621142Z

@anmonteiro oh I think I got it, something like this:

(render [this] (html [:input {:ref #(aset this (str โ€œyo-input-yo" %)}]))

baptiste-from-paris 2017-03-10T10:10:16.675760Z

Has anyone ever use (om/shared this) and in which typical use case ?

2017-03-10T10:26:43.835773Z

I just noticed :shared-fn and looks like it might be useful for something like 'current logged in user'.

baptiste-from-paris 2017-03-10T10:27:11.840170Z

ok ok

2017-03-10T10:27:51.846558Z

Pretty much all my components have something like translation to do and I need the current user's locale. It looks like it might be useful for that, until now i've been passing user down by hand.

2017-03-10T10:30:30.871953Z

In my case the root props are (:compassus.core/route :compassus.core/route-data :compassus.core/mixin-data) which doesn't seem so useful.

2017-03-10T10:35:51.922065Z

Actually, I can get current user with :shared-fn (fn [props] (println (-> props :compassus.core/mixin-data :user))). Looks like it will do the job nicely.

baptiste-from-paris 2017-03-10T10:38:30.948529Z

Ok, nice use case indeed

2017-03-10T10:49:54.057069Z

Use case number 2 - it seems a nice place to have easy access to history (pushy, lets me set routes). Until now, i assoc'd it onto the reconciler.

petterik 2017-03-10T15:28:12.243996Z

I use shared for history, like daniel said. I've also put a local-storage record in there instead of using js/localStorage directly, so I can fake it and test it in clj

๐Ÿ‘ 3
peeja 2017-03-10T20:35:34.384746Z

What do you do when two subcomponents need to read from the same key?

peeja 2017-03-10T20:36:00.390732Z

(I feel like I've asked this before but haven't found a satisfactory answer yet.)

peeja 2017-03-10T20:37:12.407331Z

I guess the best thing I've seen thrown around so far involves "placeholder" keys that the parser ignores

peeja 2017-03-10T20:37:27.411221Z

but that give the two components different places to live in the query tree

peeja 2017-03-10T20:37:51.416323Z

I wish Om queries had aliases like GraphQL ๐Ÿ˜ž

wilkerlucio 2017-03-10T21:12:00.897030Z

@peeja a lot of people lead to something like "placeholder nodes", for example, you can make your server understand any query that starts with ph to be a "placeholder node", where it goes down one level on the data tree, but logically it stays on the same position, enabling you to query like: [{:ph/view-a [:some-data :more-data]} {:ph/view-b [:other-data :more-data]}]

wilkerlucio 2017-03-10T21:12:22.902446Z

the advantage is that you keep Om.next index happy about it, since each result will be correctly marked with the component meta data

peeja 2017-03-10T21:12:40.907186Z

Oh, you'd put that on the server? I'd assume the local parser would want to clean all of that up

wilkerlucio 2017-03-10T21:13:19.916642Z

yeah, I could not figure another way to handle this, this one looks weird at first, but works nicely once you have it setup

wilkerlucio 2017-03-10T21:14:06.926966Z

@peeja there were a discussion about this before, here: https://github.com/omcljs/om/issues/823

wilkerlucio 2017-03-10T21:14:14.928569Z

you are on that one actually, hehe]

peeja 2017-03-10T21:14:22.930638Z

That must be what I'm thinking of ๐Ÿ™‚

peeja 2017-03-10T21:14:34.933576Z

I take it that hasn't led anywhere yet?

wilkerlucio 2017-03-10T21:14:56.938435Z

nop, as far as I know, nobody came up with a different solution yet

peeja 2017-03-10T21:39:26.277572Z

I suppose this also means there's no good way in Om to ask for two different things by the same key, but with different params

peeja 2017-03-10T21:39:58.284762Z

In GraphQL, for instance:

{
  empireHero: hero(episode: EMPIRE) {
    name
  }
  jediHero: hero(episode: JEDI) {
    name
  }
}
http://graphql.org/learn/queries/#aliases

peeja 2017-03-10T21:40:28.291450Z

That is, no way without implementing placeholder keys. But then you really would have to do it on the server as well.