Fork me on GitHub
#om
<
2017-01-12
>
azzikid08:01:27

hey everyone, i am wondering if there is a way to build a query that uses the results from one part of the query as the parameters to the next part of the query. i'm doing this with remote queries. here's an example: [:learn/active (:learn/sections ACTIVE-ID)]

azzikid08:01:41

so :learn/active will fetch the active id from remote, then learn/sections will take that id as a param and call the remote again to get the sections?

hlolli08:01:32

@azzikid run the first query and in componentWillUpdate look for changes in the properties (see if your remote data has arrived), if yes, then either use om/update-query! or om/set-query! to trigger a new read with new query.

hlolli08:01:44

Was thinking if it would make sense if the parser had the ability to control the merge function, many remote queries merge differently in some of my apps, that {:value/:action :remote :merge} would sound nice, but the drawbacks could be worse than the benefits of this setup.

azzikid10:01:41

@hlolli that did it! thanks!

azzikid10:01:11

new issue i have is that i am getting the error: No queries exist for component path ... my root component query has [:app/learn (om/get-query Active) (om/get-query Sections)]. the error occurs when changing the params in the Sections component with update-query! after componentWillUpdate is called.

hlolli10:01:28

@azzikid if you used set-query! did you remember to merge all the existing queries you wanted to stay? this is bit like atomic reset!

azzikid10:01:58

i actually used update-query!

azzikid11:01:44

(om/update-query! this (fn [{:keys [query params] :as q}]
                             (assoc q :params new-params))

azzikid11:01:10

@hlolli that's how i updated the query in the Sections componentWillUpdate

hlolli12:01:58

doesn't look like the query parameter inside the following query ({:learn/sections [:learn/sections]} ?pouchq) is doing much, it's outside of the join and not a parameter. But these No queries exists errors are most of the time caused by inconsistency of the root component and a child component. So look trough the queries in the root component and if the methods in the parsers are correctly setup (ex if the data is normalized/vectorized or not)

danielstockton13:01:13

I'm having trouble with a read method... I'm fetching a list of items with params to filter/limit the results. If I include both :remote and :value keys in the map I return, i get two remote requests. I'm not sure how to know whether I want to return the list from state or from remote...How do I know if params/resultset has changed?

danielstockton13:01:34

If i change the search param, I end up in an infinite loop...remote call, merge, remote call, merge, remote call..

danielstockton13:01:07

I can't just test to see if the key is in state, because it could be there but it can be the resultset from a previous query with different params...

danielstockton13:01:55

My only idea is to update the params with some unique key every time i update the query...and then i can check if this matches the last one

danielstockton14:01:07

Think that it might just be how I designed the components to update the params actually, entering into render loops

danielstockton14:01:44

Yeah, resolved it with something like this

(componentDidUpdate [this prev-props prev-state]
    (when (and (not= prev-state (om/get-state this)) (= prev-props (om/props this)))

danielstockton14:01:56

maybe i can redesign things to be more logical...

hlolli14:01:19

@azzikid I also had now for 15 minues a battle with No queries exist on path. And strangely by not passing properties into component C from B in A->B->C structure fixed it. Sometimes I feel like I don't know anything about om.next.

azzikid18:01:01

Hmm still stuck on it.

sova-soars-the-sora19:01:43

Are there any emergent resources on mastering read and mutation functions?

raspasov21:01:19

hey everyone, I just stumbled upon this article and I realized I can probably use this a lot https://facebook.github.io/react/docs/higher-order-components.html (edited) is there “a good way/recommended way” to do this in om-next?

raspasov21:01:33

(reposted from #om-next )