This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-07
Channels
- # announcements (2)
- # babashka (18)
- # beginners (45)
- # bristol-clojurians (1)
- # calva (2)
- # cider (8)
- # clara (8)
- # clj-kondo (4)
- # cljdoc (6)
- # clojure (69)
- # clojure-chennai (1)
- # clojure-dev (21)
- # clojure-europe (3)
- # clojure-gamedev (3)
- # clojure-india (1)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-norway (1)
- # clojure-spec (7)
- # clojure-uk (70)
- # clojurescript (122)
- # cloverage (5)
- # cursive (2)
- # data-science (3)
- # fulcro (21)
- # graalvm (3)
- # graphql (14)
- # jackdaw (2)
- # jobs (2)
- # lumo (2)
- # malli (1)
- # mount (1)
- # off-topic (22)
- # re-frame (2)
- # reitit (5)
- # ring (7)
- # shadow-cljs (47)
- # spacemacs (11)
- # tools-deps (127)
- # vim (16)
- # xtdb (9)
I am trying to understand how routing params are/can be used to decide what data end up in the target component's props.
Imagine I have the component tree Root -> Router -> Person
and want to show a particular person based on the URL. (Ignoring the URL <-> route part here.) So "/person/1" should show [:person/id 1]
and I do have :route-segment ["person" :id]
on Person and (if I need it?) :will-enter (fn [app {:keys [id]}] (dr/route-immediate [:person/id id]))
.
But I do not see how should this work. (1) When/how can the Person's query [:person/id :person/name :person/age]
be turned into something resolvable against the DB, i.e. [{[:person/id 1] [...]}]
? (2) And how is data passed from Root to Person? Router has :alt0 (get-query Person)
in its query but when this is resolved against the DB, there is no :alt0
top-level element. I'd assume that somehow the target's query is resolved against the Router's parent's props (in this case, the DB itself). How does this work?! (Bonus question: (3) Is this a totally wrong approach? Should I just use (nth people id-from-url)
in Root?) Thank you!!!
I do something similar, but I transact a new record into that ident before calling route-immediate …
:will-enter (fn [app {:keys [sv-id] :as params}]
(let [is-new? (= sv-id "new")
sv-id (if is-new?
(make-tempid)
sv-id)
sv-ident [:org.riverdb.db.sitevisit/gid sv-id]
editor-ident [:component/id :sitevisit-editor]]
(log/debug "WILL ENTER" sv-id "NEW?" is-new? "PARAMS" params)
(when is-new?
(comp/transact! app `[(merge-new-sv ~{:sv-ident sv-ident})]))
(if is-new?
(dr/route-immediate editor-ident)
(dr/route-deferred editor-ident
#(f/load! app sv-ident SiteVisitForm ...
so my URL is “/sitevisit/edit/new” for a new one, or “sitevisit/edit/12345" for an existing onethe down side is that :will-enter
runs 3 times so I’m creating 3 temp entities in state every time. I haven’t figured out yet a better strategy … maybe do a route-deferred and create the temp-id in the handler fn
I see that you do ± the same thing as me but I still don't understand how is the information [:org.riverdb.db.sitevisit/gid sv-id]
combined with the component's query to make a query that can be resolved against the DB....
the router changes its own query tree based on which component is currently active by reading the component’s query and then updating its own query tree with that new branch, and removing the branch of the old path
so you just need to make sure that data exists in the DB at that ident that fulfills the component’s query, and it will work
So the router changes its own query (in your case) to ...{[:org.riverdb.db.sitevisit/gid 123] (get-query current-target-lcass)}...
? I do not see that. What I see is
{::current-route `(comp/get-query ~(first router-targets))}
(map-indexed ... {(keyword (str "alt" idx)) `(comp/get-query ~s)}
but that does not work with the ident at all...Another question: How to view a Fulcro component's props? The React Dev Tools Components view shows the useless:
fulcro$value: (undefined) { {__hash: null, cljs$lang$protocol_mask$partition0$:…}, ...}
and Fulcro Inspector does not have its own Components tree view...
App State is organised by ident so use Fulcro Inspect and think in terms of idents. There might be several components in one ident family.
Hm, I have PersonList
with :ident :list/id
and in the DB there is :list/id {0: .., 1: ..}
which is the data from the initial state . But what props does the PersonList displayed on the page have?
The displayed one will be one of the ids (or many of them if it is a component that displays many). Each 'row' will have data determined by the query on the component.
In theory yes. But in practice the list is showing empty, so it is missing some props. That's why I would like to see the props it got - but don't how to. Perhaps the only solution is to add (println props)
to its code...
Yes - but doing so will just be verifying that you don't have a rendering problem. Are you saying each row only has :list/id and there should also be :list/name etc.?
Which row??? The DB contains the data it should. But my component has an empty body. So there is something wrong in the transitions of values from the client db into the component (which I have put under a router, see my previous question, though there I mention Person not PersonList)
The id (of the ident, the second thing in it) gives the row, you can print it from the component rendering function.