Fork me on GitHub
#om
<
2016-01-30
>
tawus01:01:56

How do we return errors from a remote mutation ?

dnolen01:01:02

@tawus: still getting sorted out

dnolen01:01:10

there’s no standard way to do that yet

tawus01:01:30

Is there any hack I can use for now ?

pedroiago04:01:26

are there any trade-offs in relying on life-cycle methods? how often do you guys use them?

jlongster05:01:23

shouldn't the second query work?

jlongster05:01:32

test.repl=> (om/db->tree '[:items] {:items [{:foo 1} {:foo 2}]} {})
{:items [{:foo 1} {:foo 2}]}
test.repl=> (om/db->tree '[{:items [:foo]}] {:items [{:foo 1} {:foo 2}]} {})
{:items [{} {}]}

jlongster05:01:27

also

test.repl=> (om/db->tree '[{:items [*]}] {:items [{:foo 1} {:foo 2}]} {})
{:items [nil nil]}

jlongster05:01:48

1.0.0-alpha30

andrewboltachev05:01:30

@jlongster well, 3rd params is refs, i.e. which is used for denormalizing

andrewboltachev05:01:43

it should be like

andrewboltachev05:01:03

{:item/by-id {1 ... 2 ... 3 ...}}

jlongster05:01:13

right but there is no denormalizing going on here, just plain subqueries

jlongster05:01:21

in my full app I'm passing my whole app state

andrewboltachev05:01:33

well AFAIK db->tree is for denormalizing

andrewboltachev05:01:53

not for querying

jlongster05:01:05

it runs the query and follows idents, basically. without idents, it still runs the query

jlongster05:01:10

nothing special here

andrewboltachev05:01:23

well, I were once doing sth like this

jlongster05:01:26

whether or not it came from a table is irrelevant

andrewboltachev05:01:52

and Antonio Monteiro asked me "why you passing already denormalized tree?"

jlongster05:01:11

yep in the end it will be normalized, but this caught my eye. if you can't sub-select normal maps, that's fine but seems like it should work. Might be wrong though. (only part of your query might be selecting normalized data)

andrewboltachev05:01:57

I've went through the code (of db->tree, and denormalize*) but I still can't undertand all functionality of that fn

jlongster05:01:57

it could be called "run-query" basically, but db->tree is better. no time to understand it either myself right now, easier to ask here (will look tomorrow tho)

andrewboltachev05:01:10

fact seems to be that there's no such thing as run-query, and you always have to do it yourself

andrewboltachev05:01:44

it's also seems to be strange for me

jlongster05:01:09

yeah, you have to guide it. which is why I think db->tree is better because run-query would give false impressions. but basically, I see no reason why my examples shouldn't work. will figure it out tomorrow, getting late here

cjmurphy06:01:53

@andrewboltachev: @jlongster My understanding is that to run a query you call your own parser with the query you want to execute, and it works on the normalized state and uses the read functions you have defined.

cjmurphy06:01:45

So for instance in the state I have some 'top level' things that don't have ids. And I can query their value with this function:

cjmurphy06:01:08

(defn query [kw]
  (let [res (my-parser {:state my-reconciler} `[[~kw _]])]
    (when (not-empty res) (apply val res))))

cjmurphy06:01:15

I'm calling them my-parser and my-reconciler so as not to confuse them with om/parser and om/reconciler which created them in the first place.

cjmurphy06:01:15

That a 'thinking with links' kind of query by the way.

iwankaramazow08:01:26

Is there any reason why the React lifecycle methods don't print to the console?

(defui MenuItem
  static om/Ident
  (ident [_ {:keys [id]}]
         [:navbar/items-by-id id])
  static om/IQuery
  (query [_]
         [:name])
  Object
  (componentWillUpdate [this next-props next-state]
                       (println "willReceiveProps"))
  (componentDidUpdate [this prev-props prev-state]
                      (println "did update"))
  (render [this]
          (let [{:keys [name]} (om/props this)]
            (dom/li #js {:className "pure-menu-item"
                                      :key name}
                          (dom/a #js {:className "pure-menu-link"}
                                 name)))))

iwankaramazow09:01:17

hmm nevermind, seems to work now

tawus12:01:02

I have a Root component which contains a LoginForm. When I make a change in the local state of LoginForm, the parser is called with a key belonging to the root's query. Should such a thing happen?( I might have messed up my parser or something.)

tawus13:01:02

@nblumoe: Did you solve the case where set-query was updating the parent component ?

nblumoe13:01:43

@tawus: not completly, no. But instead I have a workaround which prevents the Root rendering to override the updated query params.

nblumoe13:01:29

Was done by using subquery instead of get-query

nblumoe13:01:18

still triggering a Root rendering though. not a big deal in my particular case, because the component with the dynamic queries is a child of the Root and there isn't much overhead of re-rendering everything.

nblumoe13:01:28

still would be interested in a proper solution though.

tawus14:01:18

@nblumoe: Thanks! I am also working on a workaround.

nblumoe14:01:25

ok, let me know should you solve the Root rendering issue itself

nblumoe14:01:18

also just let me know if you have any question about what I did with sub-query (although I will only have access to the actual code again on Monday to look up details if needed)

tawus14:01:27

In my case I was following https://github.com/jdubie/om-next-router-example/blob/master/src/om_router/core.cljs example and once I tried to put a form inside a tab, it started acting strange. I think it has to do with union queries but I am not sure. I'll keep updating.

nblumoe14:01:12

Well I could reproduce my Root rendering issues, even without any routing. Also, I was using only (nested) joins, no unions

tawus17:01:47

You are right. It happened for joins too.

iwankaramazow20:01:18

I've got a query like [ {:overview/panels [:title :body [:overview/count _]]}],gets send to a remote. Does someone has any ideas on how I could parse the [:overview/count _] (thinking with links-style) out of the query on the server?