1

Does a components data have to be passed in from its parent component? Or does a components query allow the data to flow directly to the component?

I can see how a query declares what data a component needs. Does a parent component have to inspect its child component's query to find out what data to pass to it? Why do many of the examples have parent components calling something like (om/get-query ChildComponentClass)?

kevincasey
  • 249
  • 2
  • 12

1 Answers1

1

Yes. The root component is special. All data has to be passed into the root component. To achieve this your root component's query will be a series of joins. Every component's query you have in your application (that has a unique ident) must be represented as a join at the root level. If data is coming into your application it must be coming into the root. It is put there by Om Next, which takes it from your application's app state.

In an Om Next application your components are composed together as a tree. They are related to one another through their queries, specifically by joins.

At runtime the render methods of each component get their props handed down to them from the parent. The component's query will tell you what props to expect. These props are a simple map.

The answers to your questions in order are: yes, no, yes. For that third one the parent is not really inspecting its child component's query so much as already has the data for that query itself as a join, and is handing the data down to the child.

Your last question 'Why do many of the examples have parent components calling something like (om/get-query ChildComponentClass)?'. This is a join from the parent to the child, described in query syntax:

{:app/child-join (om/get-query app/ChildComponentClass)}

The cardinality of these joins is not known until runtime: it can be 0, 1 or many. If it is one then you might describe it as a lookup relationship. If more than one as a master-detail relationship. If none it could be either.

Chris Murphy
  • 6,411
  • 1
  • 24
  • 42