This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-03
Channels
- # aws (27)
- # beginners (64)
- # boot (14)
- # calva (10)
- # cider (36)
- # cljs-dev (13)
- # cljsrn (79)
- # clojure (58)
- # clojure-berlin (8)
- # clojure-france (1)
- # clojure-italy (18)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (28)
- # clojure-uk (29)
- # clojurescript (55)
- # core-async (20)
- # cursive (5)
- # datomic (105)
- # emacs (17)
- # figwheel-main (13)
- # fulcro (20)
- # graphql (4)
- # hoplon (1)
- # hyperfiddle (2)
- # jobs (7)
- # jobs-discuss (110)
- # off-topic (23)
- # pathom (1)
- # perun (2)
- # re-frame (87)
- # reitit (2)
- # shadow-cljs (8)
- # spacemacs (2)
- # tools-deps (118)
- # vim (11)
Hi Tony. With regard to my normalization troubles yesterday, I think I have more of an idea what's going on, but still don't understand what I should be doing to make this work. I made a couple of small changes to one of my two workspace cards. I removed the :target
, and asked it to load :root/person
instead of the ident I asked it to load before. I also added a resolver to my Pathom parser on the server which understands this keyword. So now the query is [{:root/person [...requested person props]}]
, and returns {:root/person {...person props}}
. This normalized as expected like in your full-stack reads video. The previous query for the specific ident targeting :root/person looked like [{[:person/id 42] [...requested person props]}]
, and returned {[:person/id 42] {...person props}}
. This one didn't normalize, and I guess it's because of that top-level join. However, this join is inserted by df/load automatically (I understand why), so I'm wondering how to make all this work? Thanks.
What does your Person
component looks like?
Like so?
(defsc Person [this {:keys [person/id person/other-prop]}]
{:query [:person/id person/other-prop]
:ident [:person/by-id :person/id]})
I also have a Root component just for the workspace card. It has a query [{:root/person (prim/get-query Person)}]
.
(df/load [:person/id 42] Person {:target [:root/person]})
Should then result in this state:
{:person/by-id {42 {:person/id 42 :person/other-prop "foo"}
:root/person [:person/by-id 42]
}
:thinking_face:Yeah, that's what I thought too, but for some reason I end up with:
{:person/id {42 {:person/id 42 :person/other-prop "foo"}}
:root/person [:person/id 42]}
It's definitely puzzling.Sure you have :ident [:person/by-id :person/id]
???
Looks like it is: :ident [:person/id :person/id]
In your Person
component?
100%. I recently added some form state stuff which does end up in :person/by-id, with the rest of the state still under :person/id. If I change the ident in Person to :person/id :person/id
, it all ends up in there as expected. That's what I've got as a workaround at the moment, but it's breaking with Fulcro idioms and will be a pain with mutations etc when I compose this component into others.
@U7YKQU7R9 I suggest you be consistent about the ids, I personally always use the format :person/id
(not :person/by-id
), I found the first to be easier to hook with pathom and avoid needing to translate, but whatever you pick I suggest you use a single one or you will have inconsistent normalized data
Ah, ok. Thanks. I assumed Fulcro took care of the translation automatically, but I think I'm misunderstand how the normalization process works.
fulcro does the normalization, but will not convert any key names, its been a default since om.next to use the by-id
pattern, but when you start using that with pathom is a problem because the ident will not match the initial data that expected there (the ident is a point of information in pathom terms), so since then I started using just the field name, for people that use by-id
they have extra resolvers to do the translation, but people have done that mostly in backwards direction (added pathom later to the game) since you are starting is good to pick one and stand by it 😉
@tony.kay My first idea was, that the param is part of the ident
, but I have to create the ident
beforehand.
My second is, that there is one component (for which i can set the ident) and the param
is coming in as a prop.
I am looking at your YouTube Video about UI-Routing now. You wrote a function ensure-routable
I want to
In my head I would like to route to a component which isn't loaded yet, but will load itself.
Like.. I get the route-param
as a param in my initial-state, which is first called, when the router routes to this component
@mroerni at the core of your problem is the fact that the query will return nil for something that is “not there”, and also won’t be able to derive an ident for it. You have to at least put something in state that will allow the proper ident to be created. Your alternative is to look at the new dynamic router in incubator. https://github.com/fulcrologic/fulcro-incubator/blob/develop/dynamic-routing.adoc. It has more “hooks” that would make implementing this easier. The only downside is that it uses dynamic queries instead of union queries. Dynamic queries are not as heavily tested in Fulcro as union queries.
@tony.kay Thanks, that is looking great.
For another solution for my problem:
How do I get route-params
to my component? Or are they only meant for use i the routing tree?
That's unfortunate. 😕