Fork me on GitHub
#untangled
<
2016-08-11
>
ethangracer21:08:15

has anyone ever run into a situation where they have a mutation that otherwise works, but when it’s paired with a call to load-data, causes a “no queries for component path” error from om?

ethangracer21:08:56

e.g.

(fn [_]
     (toggle-view :departments)
     (df/load-data this [:reports/executive-report]
             :post-mutation 'colocate-executive-report
             :params {:reports/executive-report {:survey-id id}}))

ethangracer21:08:15

(fn [_]
     (toggle-view :departments)

tony.kay21:08:22

what is toggle-view?

ethangracer21:08:28

first one throws, second one doesn't

ethangracer21:08:35

toggle-view is a mutation

tony.kay21:08:41

how? There is no component

tony.kay21:08:43

to transact on

ethangracer21:08:48

#(om/transact! this [(report/set-survey-view ~{:view %})])

tony.kay21:08:09

what is "this", and is it the same "this" as the visible "this"?

ethangracer21:08:31

this is the current component on the screen

tony.kay21:08:43

for toggle-view?...how?

tony.kay21:08:00

oh, is it earlier in a let, or something?

ethangracer21:08:19

yeah, so a more complete sample

tony.kay21:08:55

is toggle view causing the component to disappear?

ethangracer21:08:18

(render [this] 
  (let [toggle-view #(om/transact! this `[(report/set-survey-view ~{:view %})])]

   (dom/button #js {
                    :onClick (fn [_]
                               (toggle-view :departments)
                               (df/load-data this [:reports/executive-report]
                                 :post-mutation 'colocate-executive-report
                                 :params {:reports/executive-report {:survey-id id}}))}
     "Button text")))

tony.kay21:08:20

(from the dom)

tony.kay21:08:57

or otherwise change a union query to no longer contain the rendering component

ethangracer21:08:58

it’s causing a different function to be called, but is rendering the same component

ethangracer21:08:17

as in, different branch of dom nodes to be rendered

ethangracer21:08:22

but same component

ethangracer21:08:37

and, when there is no data fetch, it works just fine

tony.kay21:08:01

I understand that, but load data happens on a different time scale. toggle-view happens immediately, and then a rerender is scheduled. Does the new view rely on data that is to-be-supplied by the load?

ethangracer21:08:49

shows a loading marker if the data hasn’t been loaded yet

tony.kay21:08:06

are you stomping on something that is already at :reports/executive-report?

tony.kay21:08:18

try loading to a diff key

tony.kay21:08:51

in other words, try to isolate it to the fact that there are 2 transacts, or the fact that the data is the problem

tony.kay21:08:58

I suspect the latter

ethangracer21:08:00

pretty sure i’m not stomping on data, but i’ll try to see how the data or the post processing might be mucking with something it shouldn't

therabidbanana22:08:47

We don't really use load-data directly very often

therabidbanana22:08:26

Generally we use a named mutation with df/load-data-action instead.

therabidbanana22:08:47

Then we can do something like:

#(om/transact! this `[(report/set-survey-view ~{:view %})
                                               (executive-report/reload %)])]

therabidbanana22:08:49

I think we needed to do that to avoid the above kind of error you describe, but I don't recall for sure

ethangracer22:08:10

@therabidbanana: thanks, that’s interesting i’ll give that a try

therabidbanana22:08:17

Added benefit - it made it really easy to build routing - we model HTML5 history events as just transactions on the reconciler, so having load data mutations makes that system work pretty well

ethangracer23:08:56

@tony.kay: just fyi, the solution @therabidbanana describes above did fix the problem. Not sure if that is necessarily untangled’s design intention, if this is a bug, or if it’s just a function of how om is scheduling renders