Fork me on GitHub
#om
<
2017-02-07
>
hlolli08:02:16

if you see some bugs or old versions lurking around, dont hesitate to let me know in pm. I believe I was having some problems with the scss last time, I've been switching entierly to node-sass for sass compilation.

astrashe15:02:49

I have a question about an example in the quick start. In the "Naive Design" code in the "Adding State" section, it seems that :count from @app-state is finding its way into Counter's props. How does that work? Does the reconciler just pass @app-state as the props because we aren't using a parser?

baptiste-from-paris15:02:03

#newbie question I can’t normalize my init-data and I don’t understand why There are persons and 2 lists in a dashboard item

(def init-data
  {:list/one [{:id 1 :name "John" :points 0}
              {:id 2 :name "Mary" :points 0}
              {:id 3 :name "Bob"  :points 0}]
   :list/two [{:id 2 :name "Mary" :points 0 :age 27}
              {:id 4 :name "Gwen" :points 0}
              {:id 5 :name "Jeff" :points 0}]
   :dashboard/items [[:list/by-id :list/one]
                     [:list/by-id :list/two]]})

(defui Person
  static om/Ident
  (ident [this {:keys [id]}] "Return the ident for this component"
    [:person/by-id id])
  static om/IQuery
  (query [this]
    [:name :points :age]))

(defui ListPerson
  static om/Ident
  (ident [this {:keys [id]}]
    [:list/by-id id])
  static om/IQuery
  (query [this]
    `{:list/by-id ~(om/get-query Person)}))

(defui RootView
  static om/IQuery
  (query [this]
    (let [subquery (om/get-query ListPerson)]
      `[{:dashboard/items ~subquery}])))
when I run
(om/tree->db RootView init-data)
I got
{:list/one [{:id 1, :name "John", :points 0} {:id 2, :name "Mary", :points 0} {:id 3, :name "Bob", :points 0}],
 :list/two [{:id 2, :name "Mary", :points 0, :age 27} {:id 4, :name "Gwen", :points 0} {:id 5, :name "Jeff", :points 0}],
 :dashboard/items [[:list/by-id nil] [:list/by-id nil]]}

baptiste-from-paris15:02:42

might be too large, sorry for that

danielstockton15:02:52

Technically, not because there is no parser, but because there is no query.

anmonteiro15:02:12

@baptiste-from-paris: you probably forgot to place your list query inside a vector

baptiste-from-paris16:02:57

thx @anmonteiro , does not work for me but I keep trying 🙂

levitanong17:02:52

@baptiste-from-paris I would also look at the fact that your ListPerson query also makes a join around :list/by-id, which is probably not what you want to do.

levitanong17:02:55

@baptiste-from-paris further, you’re trying to define your ListPerson ident by looking at an id. But your lists don’t have id keys. The individual list items do, but not the lists as a whole. Try logging the value of the second argument of ident.

(ident [this list-person]
  (println list-person))

baptiste-from-paris17:02:48

it gives me =>

[:list/by-id :list/one]
[:list/by-id :list/two]

levitanong17:02:41

Since the thing itself is the ident, all you need to do is:

(ident [this list-person-ident]
   list-person-ident)

levitanong17:02:27

but of course, i’m not sure this will fix the problem.

levitanong17:02:42

but it would be useful to correct your thinking that ident is always {:keys [id]}

baptiste-from-paris17:02:53

nope, but you are helping me understand more

baptiste-from-paris17:02:12

I know, ident is about identity/unicity right ?

levitanong17:02:06

wait a minute.

baptiste-from-paris17:02:12

I am just learning om.next and I am looking for the correct workflow for building my UI

levitanong17:02:14

i think the problem is you’re trying to normalize it already

levitanong17:02:36

(def init-data
  {:dashboard/items 
   [{:list-id :list/one 
       :list-values [{:id 1 :name "John" :points 0}
              {:id 2 :name "Mary" :points 0}
              {:id 3 :name "Bob"  :points 0}]
    {:list-id :list/two 
       :list-values [{:id 2 :name "Mary" :points 0 :age 27}
              {:id 4 :name "Gwen" :points 0}
              {:id 5 :name "Jeff" :points 0}]]})

levitanong17:02:54

ugh, indentation in slack is hard

levitanong17:02:16

(def init-data
  {:dashboard/items 
   [{:list-id :list/one 
     :list-values [{:id 1 :name "John" :points 0}
                   {:id 2 :name "Mary" :points 0}
                   {:id 3 :name "Bob"  :points 0}]
     {:list-id :list/two 
      :list-values [{:id 2 :name "Mary" :points 0 :age 27}
                    {:id 4 :name "Gwen" :points 0}
                    {:id 5 :name "Jeff" :points 0}]})

levitanong17:02:56

here, your List ident will be

(ident [this {:keys [list-id]}]
  [:list/by-id list-id])

levitanong17:02:35

your persons weren’t being normalized because your ListPersons were already manually normalized, and om.next couldn’t make the connection

baptiste-from-paris17:02:50

getting closer but not there yet =>

{:dashboard/items [[:list/by-id
                    {:list-id :list/one,
                     :list-values [{:id 1, :name "John", :points 0}
                                   {:id 2, :name "Mary", :points 0}
                                   {:id 3, :name "Bob", :points 0}]}]
                   [:list/by-id
                    {:list-id :list/two,
                     :list-values [{:id 2, :name "Mary", :points 0, :age 27}
                                   {:id 4, :name "Gwen", :points 0}
                                   {:id 5, :name "Jeff", :points 0}]}]]}

levitanong17:02:59

@baptiste-from-paris i’d like to continue helping, but it is already time for me to sleep. I’ll get back to you in 8 hours 😉

levitanong17:02:02

good luck, man!

baptiste-from-paris17:02:12

ahah, that’s more than enough 😉

levitanong17:02:28

happy to help

cjmurphy17:02:28

@baptiste-from-paris: The person query should have an :id in it. Person's ident is expecting an :id.

baptiste-from-paris17:02:22

my person’s ident is never called

baptiste-from-paris17:02:30

don’t understand why

devth18:02:45

i have some props that contain idents e.g. {:members [[user/by-id 1] [user/by-id 2]]}. i'm passing each item in members to a child component that has an om/Ident and an IQuery but the ident is not replaced with the props that i'm querying – e.g. [:db/id :user/name] – the props in the child just show up as [user/by-id 1]... any idea why?

devth18:02:10

however: if i remove the om/Ident on the child component it happily obtains correct props

anmonteiro18:02:52

@devth are you calling db->tree in the parser to get the actual props?

devth18:02:42

(someone else's code base - i'm not sure why)

devth18:02:45

elsewhere Idents work as expected

devth18:02:56

(and i needed them, or else i'd get errors)

anmonteiro18:02:10

if the app state is normalized, you need to call db->tree to get the actual props, and not the references

devth18:02:38

ok. i'll ponder this and try to figure out why it worked in another case.

cjmurphy18:02:34

@baptiste-from-paris: I'm not surprised. Non-normalized data is actually supposed to be normalized in that objects are supposed to refer to one another by ids. What db->tree does is put your data into default database format. So I'm saying even your non-normalized data should be normalized, at least in so far as it uses idents to refer from one object to another. That's the way I've always done it anyway.

cjmurphy18:02:35

So :list-values [{:id 1}{:id 2}{:id 3}]

cjmurphy18:02:09

I'm a bit rusty and not sure about that key with your data, but whatever the key is it needs to be repeated and have the actual data in it, so :list-values [{:id 1 :name "John" :points 0} {:id 2 :name "Mary" :points 0}{:id 3 :name "Bob" :points 0}]

cjmurphy18:02:19

@baptiste-from-paris: For example in this SO answer http://stackoverflow.com/questions/35554592/normalization-and-idents-in-om-next see what is done with :app/messages, a key inside :app/session.

baptiste-from-paris18:02:57

ok, ill take a look after lunch and let you know, thx a lot

pat23:02:16

For components without queries, is there any reason to use om/computed? You can give them anything you want as long as you dont transact from them, correct?

anmonteiro23:02:43

you can also transact! from them I believe

anmonteiro23:02:08

the transaction will actually happen from a parent

anmonteiro23:02:37

or to be precise, the nearest parent which has a query