This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-04
Channels
- # announcements (7)
- # beginners (37)
- # boot (6)
- # calva (13)
- # cider (13)
- # cljdoc (52)
- # cljs-dev (9)
- # clojure (117)
- # clojure-europe (3)
- # clojure-italy (12)
- # clojure-nl (21)
- # clojure-russia (8)
- # clojure-spec (77)
- # clojure-uk (20)
- # clojurescript (142)
- # community-development (6)
- # cursive (5)
- # datomic (13)
- # emacs (9)
- # figwheel-main (20)
- # fulcro (33)
- # graphql (11)
- # instaparse (6)
- # klipse (1)
- # off-topic (7)
- # om (8)
- # quil (7)
- # re-frame (11)
- # reagent (39)
- # reitit (10)
- # shadow-cljs (36)
- # spacemacs (3)
- # test-check (3)
- # tools-deps (83)
- # utah-clojurians (31)
- # vim (14)
I am having a strange issue with how idents are looked up in the application I am working on. I cooked up a minimal example to reproduce the issue:
(def app-db
{:nested {:unit {:task [:task/id 1]}}})
(prim/db->tree [{[:nested :unit] [{:task [:task/name]}]}] {} app-db)
; => {[:nested :unit] {:task [{} {}]}}
Note the vector with two empty maps under task
. Why is that?
I investigated some alternative scenarios:
(def app-db
{:task [:task/id 1]})
(prim/db->tree [{:task [:task/name]}] {} app-db)
; => {}
(as I would expect)
(def app-db
{:nested {:unit {:task [:task/id 1]}}
:task/id {1 {}}})
(prim/db->tree [{[:nested :unit] [{:task [:task/name]}]}] {} app-db)
; => {[:nested :unit] {:task {}}}
Actually, I have an idea of what might be going on: when the table doesn’t exist, Fulcro thinks of the ident as a vector of elements and performs the join on that? But if that’s the case, it begs the question: is there a way to tell Fulcro “no, treat this as an ident”? (beyond creating the table in the database, like I did)
This wouldn’t explain why my second example behaved the way it did though:
(def app-db
{:task [:task/id 1]})
(prim/db->tree [{:task [:task/name]}] {} app-db)
; => {}
Related to https://github.com/fulcrologic/fulcro/find/develop#L1195 I think
And could someone point me at the place in the codebase where Fulcro resolves idents please? 🙂
@hmaurer the only way for fulcro to know if something is an ident/join is if there is a component with an ident involved
when you do {:some-k (prim/get-query ChildComponent)]
in a parent component, when building it’s query, fulcro tacks on some meta data on the query, specifying that it is in fact a join with such and such ident so look there
when you pass in a query by hand, like you’re doing there is no metadata, so fulcro doesn’t notice the join
you need to call db->tree
like so (prim/db->tree (prim/get-query SomeComponent) ...)
and yes you need to have a :task/id
table
Ah, interesting. Thanks @currentoor!
for example i have this component with this structure
ui.cljs:307 (prim/get-query OrderSummaryModal) => [:order/id
:fulcro.incubator.pessimistic-mutations/mutation-errors
{:order/payments
[:payment/id
:payment/amount
:payment/change
:payment/kind
:payment/cc-pan
:payment/created-at
:payment/cc-brand]}]
that’s the query
and here’s the meta
(meta (prim/get-query OrderSummaryModal)) => {:component ucv.ui.mobile-pos.payment-flow.ui/OrderSummaryModal,
:queryid "ucv.ui.mobile-pos.payment-flow.ui/OrderSummaryModal"}
so from the meta data fulcro can get the component class
and from that it can figure out what the ident key is (if it’s an ident component)
otherwise fulcro has no way of knowing if it’s a join and what the ident key/fn is
because even though we usually make an id
type key the ident key/fn it doesn’t have to be
it’s totally arbitrary
you could make an ident key out of :foo/name
that’s a nested query yes, but it doesn’t know that it’s a join vs a nested query
I found this bit of code this afternoon: https://github.com/fulcrologic/fulcro/blob/develop/src/main/fulcro/client/primitives.cljc#L1195
i’ll make a quick example
;; this query
[:title {:child [:id :name]}]
;; can be satisfied by this
{:title {:child {:id 1 :name "foo"}}}
;; or can be satisfied by this
{:title [:child/by-id 1]
:child/by-id {:id 1 :name "foo"}}
the meta data tells fulro that it’s the latter you want
@currentoor oh right. I’ll play a bit with this / check the metadata on queries
no worries