Fork me on GitHub
#fulcro
<
2017-10-14
>
mitchelkuijpers10:10:13

@tony.kay We only use dynamic queries with DynamicRouter

mss12:10:31

hey all, new to fulcro (new-ish to om next) and really excited to play around with the library. had a question on how to handle subcomponent queries. per the sanity checklist (https://github.com/fulcrologic/fulcro/blob/develop/docs/CheatSheet.adoc#sanity-checklist), the guide says something like:

– Every child's query is composed in using an "invented" join name in the parent: 
    (query [this] [{:invented-join-prop (om/get-query Child)}])
– Queries compose all the way to a single Root
– Every child's props are pulled from om/props and passed to that child's factory for rendering
what do most peoples’ parsers look like if you’re inventing named join props for each subcomponent’s query? do you just dispatch (assuming a multifn) based off the invented prop, or do you somehow mutate the query ast to pick out what props you actually want? I’m just playing around with fulcro at this point, and would really love some insight as to why this is a suggested practice from people who’ve gotten knee deep already. in my mind, the more natural thing would be to do exactly what’s not recommended in the docs – (query [this] (om/get-query OtherComponent)). clearly that’s wrong for some reason, would love to understand why. thanks in advance for any insights and help!

tony.kay14:10:53

@mss Welcome! So, the better place to start is in the GettingStarted doc on the main repository. There are also quite a few youtube videos that walk you through the basics. The answer to your question is that each component should ask for what it needs. If the component is asking for what some other component needs, then the relationship is one of child-parent. If the parent doesn’t need anything for itself, then it shouldn’t have a query.

tony.kay14:10:45

There are a number of technical details for why the scheme is the way it is, but it is simpler to just think of it that way: a component only has a query if it has a specific data need (e.g. Person might ask for :person/name). A component like PersonList doesn’t have any idea what a Person wants, but it may have needs of it’s own (e.g. PersonList wants :list/sort-by), in addition to the people in the list {:list/people (om/get-query Person)}.

tony.kay14:10:36

You might also have two sets of people (PersonList asks for [{:list/friends (om/get-query Person} {:list/enemies (om/get-query Person)}]) and combines them into the list, perhaps

tony.kay14:10:39

In any case, does it conceptually make sense for a component PersonList, whose job is to be a list of people, to have only a query stolen from Person?

tony.kay14:10:14

From a DRY perspective one could argue that you only need people in a person list…but it already is DRY, the requirement is just that you create a join when going from parent to child. You are not duplicating code, you’re creating a graph query that matches the graph of data which also happens to match the graph of the stateful components in the UI. This is critical to the reasoning model, normalization, and other things, and is the key to the resulting simplicity of the overall model.

tony.kay14:10:56

@mitchelkuijpers Just FYI: dynamic queries in Om break the support viewer, because they store the query by component reference in app state.

tony.kay14:10:18

they also technically break history and re-rendering by updating top-level react keys

mitchelkuijpers14:10:19

We currently don't use the support viewer, and are looking at dynamic routing because we need to split our app

mitchelkuijpers14:10:27

But nothing in production yet

tony.kay14:10:48

yep…just want you to be aware. I’m working on some fixes, but it may result in Fulcro 2.0 being more of a fork of Om instead of using Om.

mss16:10:39

@tony.kay really appreciate the response. that all makes sense

juno23:10:53

Hi, I’m trying to prototype an app using the fulcro-template as a base and trying to integrate fulcrologic/semantic-ui-react-wrappers and having issues. I started with the cards trying to see how I can integrate semantic-ui and no issues there but if I require semantic-ui in LoginPage I get an error as such Couldn't load Clojure file src/main/fulcro_template/ui/login.cljc java.io.FileNotFoundException: Could not locate fulcrologic/semantic_ui/factories__init.class or fulcrologic/semantic_ui/factories.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.