This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-10
Channels
- # admin-announcements (2)
- # arachne (2)
- # beginners (53)
- # boot (52)
- # cider (7)
- # cljs-dev (61)
- # cljsrn (12)
- # clojure (61)
- # clojure-greece (22)
- # clojure-nl (16)
- # clojure-russia (103)
- # clojure-spec (84)
- # clojure-uk (15)
- # clojurescript (137)
- # community-development (14)
- # cursive (4)
- # datomic (14)
- # devcards (6)
- # euroclojure (3)
- # funcool (26)
- # hoplon (27)
- # jobs (4)
- # lambdaisland (1)
- # leiningen (1)
- # om (75)
- # onyx (77)
- # planck (15)
- # proton (2)
- # re-frame (23)
- # ring-swagger (9)
- # schema (1)
- # specter (95)
- # untangled (124)
- # yada (27)
In a send
that's fetching a value for an ident, what sort of structure should I give the callback to get it to merge correctly?
Ah, of course. I want to be returning it like the result of a query, not in the shape that it's normalized to in the db.
I think this behavior depends on if you’ve overridden :merge-tree
in your reconciler also. And if your app is more complex you might need to provide your own smarter merge function.
When running a parser recursively, the data is keyed with it’s parent. How do I then select the right portion from a child-parser without mentioning the parent?
@hkjels: example?
You can modify the ast, if it's a remote you're talking about
hi guys, does any on experience with link query that instead of return just the key in link query, it returns the whole query as key. For example in my case:
;; query `[[:route/data ~'_]]
;; value returned in props {[:route/data _] {:_type :new}}
I expect it should be {:route/data {:_type :new}}
, shouldn't it ?That would go against the idea that whereever a key can go, a link can go instead. Also I think of both of them as indivisible. It would be inconsistent to make the request with a link and get back a key(word).
@cjmurphy: thanks for the response. How about the link in this example https://github.com/omcljs/om/wiki/Thinking-With-Links! . Does a link in a component with ident interpreted different than the one from component without ident ?
And thanks for reminding me about ~'_
- no wonder I've had so much trouble - forgotten you had to do that.
I wouldn't think so. Just using a link instead of a keyword in the query has no effect on the ident. The link isn't used in the ident in that example.
The great thing about links is that you can just put them in your state, then put them in different components all over the place. Good for information that isn't part of the tree.
yeah, link is very convenient. I might not explain things clearly, let's put the example above in comparison:
(defui Item ;; with ident
static om/Ident
(ident [_ {:keys [id]}]
[:item/by-id id])
static om/IQuery
(query [_]
'[:id :title [:current-user _]])
Object
(render [this]
(let [{:keys [title current-user]} (om/props this)] ;; we can use current-user here instead of [:current-user _]
(dom/li nil
(dom/div nil title)
(dom/div nil (:email current-user))))))
(defui Item ;;without ident
static om/IQuery
(query [_]
'[[:current-user _]])
Object
(render [this]
(let [{:keys [current-user] :as props} (om/props this)]
(prn "value" (get props '[:current-user _]) ;; now the value is in [:current-user _]
))
I'm not sure this is normal, it looks a bit weird to me 😛 . That's my concernI've always used links in components that have idents so never seen your without ident example before. Seems like an interesting quirk that will have an explanation 😛
yeah, it's true ... I find I do have some weirds way using om next xD. I will find another way to solve this problem mean while putting it here to see if there is any explanation for this. Thanks for collaborating as always 😄
@ethangracer: fixed your bug in https://github.com/omcljs/om/pull/696/
@nxqd: pretty sure it’s unrelated to components having idents or not. You’ll only get links resolved if you’re using db->tree
. Don’t expect magic to happen otherwise
@jasonjckn: I'm pretty sure you can't literally transact inside an :action
. Would it make sense to extract the behavior from the other mutation into a function and call it from both :action
s?
As I understand it, Om components aren't allowed to "steal" a child's query. That is, you query can't just be (query [this] (om/get-query ChildComponent))
. I understand that that's true, but I don't entirely understand why. Can someone explain that (or point me to something)?
@peeja: the problem with stealing queries is that there’s no longer composition on that path in the tree
there will be no path from to root until that component
the path will end in the component that’s stealing the query
I hope I’m explaining myself well enough
Ah, right, because you need a path of nodes in the query that are annotated with the components?
well that’s just an implementation detail
the reason is simply that you want to be able to compute the whole query for the application
if B is a child of A, and A steals B’s query, then B is just no longer part of the equation
(defui Root
static om/IQuery
(query [this]
[{:a (om/get-query A)}]))
(defui A
static om/IQuery
(query [this]
[(om/get-query B)])) ;; WRONG
(defui B
static om/IQuery
(query [this]
[:foo :bar]))
path from Root to A is [:a]
(hint: the join key)
what’s the path from A to B?
the answer is none, it can’t possibly know how to compose that path, and e.g. how to pass props to it
It feels just as wrong to me to just have Root use B's query directly, though. Root shouldn't know that what A needs is B's props.
I don’t understand the question, sorry
The solution as I've seen it is:
(defui Root
static om/IQuery
(query [this]
[{:a (om/get-query B)}]))
(defui A)
(defui B
static om/IQuery
(query [this]
[:foo :bar]))
But now Root gets a query from a component it doesn't render, which seems wrong. It has to know that A renders a B to know which component to get the query from.
depends on what the use case is
can also get-query
Root -> A -> B
where A joins B’s query
but it needs to have a join key, such that there’s a path
Huh. I'm not sure how that would actually work in the parser, but I assume it would take a more sophisticated example to see what it takes. 🙂
@anmonteiro: Thanks for the explanation!
@anmonteiro: thanks, much appreciated!
@ethangracer: install my branch locally if you wanna use that https://github.com/anmonteiro/om/tree/recursive-unions
got it, awesome, back to fully functional over here
In an app that has routing, the root query is going to change drastically from "page" to "page". Doesn't that throw off normalization?
Ah, does Om normalize data coming back from remotes based on the query that caused the read, rather than whatever the root query is at the time the callback is called?
@peeja: that’s right, you can pass the query as a 2nd arg to the callback in send
I've got this demo app I'm playing with where I'm showing a list of items, and the details for a selected item from the list. If there's no item selected, I want to show no details. I'm storing the ident of the selected item as a query param. That works great, except: I don't know how to have a nothing-selected state. https://github.com/Peeja/om-next-starter/blob/list-noodling/src/om_starter/core.cljs#L84-L100
Here, I'm defaulting the selected item to [:item/by-name "B"]
. If :selected-item-ident
were instead nil
(which is what I'd like), the query would no longer be valid.
Is there a good way around that? I could set-query!
the entire query instead of the params, but that seems heavy-handed.