Fork me on GitHub
#om
<
2016-06-04
>
yusup10:06:23

Hi, is there any non-trivialish Om/Next app source code available to read ? Any recommendations ? thanks

dobladez16:06:24

Newbiew here: I want to build a fairly typical ItemList component. In examples I see, the root component has the query for the data, and ItemList declares no queries. Now, if I want ItemList to transact! (to add/remove items), it fails with transact! invoked by component [object Object] that does not implement IQuery.

dobladez16:06:53

I discard calling transact! from the Root component. The logic doesn't belong there

dobladez16:06:48

I want to give ItemList a query, but cannot figure out the right way. The query for the top-level key (say, :item/list) is already on the Root query. I cannot query for the same top-level key on ItemList, right?

dobladez16:06:34

I'm surely missing some basic concept here 😕

cjmurphy16:06:04

@dobladez: Your root queries should actually be repeated. (and @yusup) - to see how to structure your application see the Kanban demo.

dobladez16:06:02

thanks... I'll dig deeper into that app. Now, If I simply declare the same query on ItemList, after calling transact! I get No queries exist for component path ... ... this is why I thought it was not the right way to do it

anmonteiro17:06:03

@dobladez: can’t your ItemList be the root component?

dobladez17:06:29

thanks, but not really... I'd need my app's root to hold common stuff, and have many sub-widgets (ItemList being one of them)

anmonteiro17:06:56

@dobladez: I read your initial question again. I’d do the following: 1. removing items should be the easiest. each item knows how to remove itself so transact! on that 2. adding items can be done by passing the transact! call as a computed prop from the root to the ItemsList component

dobladez17:06:16

yeah, thought about 2. as an options... but wouldn't that pollute the Root component with stuff from all over the app?

dobladez17:06:01

I'm thinking of a typical "admin" app, with a menu on the left to going to different admin pages... some of those pages showing a list of items (say, Users). I cannot think of the top-level component having that detailed knowledge of all sub-components

dobladez17:06:51

I apologize if I am asking dumb questions. I'm pretty new to both Om and React. But after going through the docs and tutorials, I couldn't really find a good way to structure an app like that

yusup17:06:18

thanks, I will look into that.

cjmurphy17:06:12

@dobladez: Adding is affecting all the items because it is adding to the list of them. The place where the list is is the parent (the root component in your case). So when you (transact this, the this needs to be the parent/root component, because it is the 'holder' of all the items.

dobladez17:06:13

right... I'm calling transact from ItemList, not from Item

dobladez17:06:02

however, the root component has the query. I'd like to have the query on ItemList (too?)

cjmurphy17:06:04

Oh okay - as long as parent, forget I said root,

cjmurphy17:06:02

Yes the root has joins to all the queries - see the Kanban demo - all data is loaded in from the top (root component), and you deliver the props down the rest of the inverted tree.

dobladez17:06:24

So, if my hierarchy is Root->ItemList->Item, the query for ItemList could look like [:item/list] (ignoring Item for now)

dobladez17:06:08

right? Then, the query at Root cannot simply include [:item/list] and pass it on. It worked for me when it first initializes , but after a transact, I get No queries exist for component path Root ItemList which I don't event know how to decode yet

dobladez17:06:13

I guess Root should query for something like [ { :xyz [ :item/list ] }] (or the equivalent [{ :xyz (om/get-query ItemList)] })

cjmurphy17:06:30

The root query should consist of all joins - so {} needs to be there.

dobladez17:06:03

right, typo... editing the msg

cjmurphy17:06:05

The same joins repeated on lower components, just not all in one as they are at the root component.

dobladez17:06:21

I'll keep banging at it... I'm trying to figure out what to do with :xyz above 🙂 I have nothing to join from! it's just a list I read from a top-level key