Fork me on GitHub
#om
<
2016-08-12
>
akiel15:08:19

I have an Indexer question. Can someone help me?

danielstockton15:08:11

@akiel ask your question and we'll see

akiel15:08:06

If I have a list of items were each item is a component with om/Ident, I can find the individual component rendering one particular item with (om/ref->components r <ident>). So far so good.

akiel15:08:02

But if I render only one item (say in a detail view) in the same manner, I can’t find the component with the items ident.

akiel15:08:38

Instead of that, the ident under which the component is indexed is [:my-item nil].

akiel15:08:17

And my question is: why is there a difference? At the end I have an issue with re-rendering on new data from remote. And I think it’s related to the fact that the reconciler can’t find the component to re-render because it’s only indexed under [:my-item nil] and not under [:my-item <id>].

ethangracer15:08:42

I realize that if you want to call multiple transactions, you’re supposed to list them all under the same call to transact! like so:

(om/transact! this [(tx/first) (t/second {:some :params})])
I’ve noticed that if, instead, you make multiple calls to transact! in quick succession, it can cause a console error:
(om/transact! this [(tx/first)])
(om/transact! this [(tx/second {:some :params})])
;; => “No queries exist for component path …” error displays in the console
Anyone have insight into why that might be happening? I know that transact! schedules re-renders, but shouldn’t the behavior of these two code samples be identical?

ethangracer15:08:40

@akiel: are you sure that the id exists for that component? it isn’t being overwritten by the server somehow? or being pulled improperly from app state?

akiel16:08:10

@ethangracer: my server returns {<ident> <data>} but the reconciler can’t find a component which has the ident as ref.

akiel16:08:03

Do you have an example in your application were you query a remote for an ident? I can’t find such examples.

ethangracer16:08:06

I do, unfortunately it’s for work so I can’t share

ethangracer16:08:39

but the gist is [{[:todo/by-id 5] [:title :done?]}]

akiel16:08:47

@ethangracer: regarding your transactions: I can’t say something about your problem but usually I would try to merge mutations into one trasnaction.

ethangracer16:08:48

and it does successfully merge that data back

akiel16:08:32

yes in my case the data is also sucessfully merged, but no re-render is done

ethangracer16:08:46

is the component that you’re trying to re-render already on the screen?

ethangracer16:08:55

to my knowledge the indexer only keeps track of currently rendered components

akiel16:08:10

yes the component is already rendered with partial data - let me explain

akiel16:08:17

I have a list of items which queries only a subset of the items data. Than I click on one item which renders a component showing more data of this item. First it’s rendered with the subset of the data already available in the state. Than the remote query is issued. The remote answers with the full data which is sucessfullt merged. But no re-render is done.

akiel16:08:10

I have debugged the reconciler and it just can’t find a component which the appropriate key.

akiel16:08:56

@ethangracer: I found my problem. I just forgot to query for my item’s id so the ident returned was [:my-item nil]. It’s just super easy to make such simple mistakes not noticing it… 😟

ethangracer16:08:13

that’ll do it. definitely been there, it’s hard to catch those.

akiel16:08:38

There is already a warning if one returns invalid idents but that doesn’t check for nil id values. I think I’ll suggest an addition.