This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-04
Channels
- # announcements (1)
- # architecture (18)
- # aws (7)
- # babashka (63)
- # beginners (38)
- # bristol-clojurians (1)
- # circleci (1)
- # clj-kondo (10)
- # clojars (4)
- # clojure (159)
- # clojure-berlin (3)
- # clojure-europe (4)
- # clojure-italy (7)
- # clojure-losangeles (6)
- # clojure-nl (7)
- # clojure-spec (3)
- # clojure-uk (109)
- # clojurescript (54)
- # css (1)
- # cursive (38)
- # data-science (2)
- # datascript (3)
- # datomic (14)
- # docker (2)
- # duct (11)
- # fulcro (47)
- # jobs (8)
- # jobs-discuss (3)
- # kaocha (4)
- # malli (3)
- # nyc (2)
- # off-topic (30)
- # overtone (3)
- # re-frame (17)
- # reagent (33)
- # shadow-cljs (29)
- # spacemacs (3)
- # specter (4)
- # tools-deps (13)
- # xtdb (13)
@holyjak Have you watched this video??? https://www.youtube.com/watch?v=mT4jJHf929Q&list=PLVi9lDx-4C_T_gsmBQ_2gztvk6h_Usw6R&index=9&t=1271s
itâs very old, and was for pre-fulcro (Untangled)âŚbut the concepts are all still what weâre using. Just ignore the Om Next comments.
I should really re-do this with nice slides and current APIâŚit would clarify a lot of things for ppl, I think.
The ârootâ is special, but (load! this :some-key SomeClass)
loads INTO the rootâŚbut the class can be nil
if you donât need normalizationâŚso that can be easily used to load something into the root without needing a dummy class.
There is no need to use a join on link queries. [:root-key '_]
is perfectly fine, and will pull the entire opaque value (scalar, map, etc.) from the root
Loads always default to the root, and the :target
option of load changes that to a diff node in the graph
The one complication with link queries is that the client query engine will not flow into a component that has only a link query, but no data of its own. This is explicitly warned about in the book: http://book.fulcrologic.com/#_a_warning_about_ident_and_link_queries
For those of you keeping track of RAD: I got some of the validation stuff ironed out today, and cleaned up the generated UI code a bit more. The demo is becoming pretty capable.
The coolest thing to come out of all of this cleanup is that defsc-form
now just generates a Fulcro component with its own state machine and route that is a âdrop inâ for regular applicationsâŚyou can just drop a form into a top-level router (actually subrouter as well if you understand the routing composition). It technically does not require any of the RAD back-endâŚjust Pathom resolvers and an implementation of the save-form mutation (which just sends a form-state diff, which is easy to transform to db writes).

documentation is spotty, but this stuffâs going to be quite useful to anyone writing Fulcro apps, even if they donât want half of RADâs services
@tony.kay I've watched the video but still struggle to understand how to load (parameterized!) data into the root. The use case is: 1. I have the user's ID (from the URL) 2. I want to load his details, ie user-ID => {:id.., :fname..} ; there is only ever a single user so it should be I guess at the root of the tree, eg :global/current-user 3. In my component (under a router, rooted to iff there is a user ID) I want to use the ID and fname So I need something like
`(df/load! SPA
:global/current-user ; where in the tree root
[:user/id :user/fname] ; what attributes I want
{:input [:user/id "id123"]}) ; the inputs Pathom needs`
I don't see how to do that. I'm missing something obvious...@holyjak two ways: 1. create a component with the query you want. and use it in load. or 2. drop the subquery and use nil, but have your resolver for that key just return the full map of what you want.
The 3rd option is to use the internal load mutation to write exactly the query you want. That isnât in the general API because it can easily break normalization.
(df/load! SPA :global/current-user nil {:params {:input [:user/id 123]}})
âŚbut Iâm not sure why youâd be saying âcurrent userâ and then passing an id of a userâŚshouldnât the session on the server figure that out?
The load youâre running looks more like it should use:
(df/load! SPA [:user/id 123] User {:target :global/current-user})
but if youâre really trying to do some kind of session thing, then the server should know who the current user is already, and pathom doesnât need that as input from the client, but it should derive it from the ring request itself (session) (which your middleware can mix into the pathom env)
Thanks a lot! No, this isn't a session. In reality the user has a secret ID/token (they get a magic url and we extract it from there) we use to fetch some extra data before showing them a list of options and sending them off.
What I do currently is as you propose having a User component that is only used for the sake of the query. But it felt hackish...
I made up the :input
param just for the purpose of demonstration. I assume ld that :params could possibly be used for that but could find the docs explaining them in detail. I'm sure they are out there somewhere in the book or docstrings...
If I go with (2) then I need to write a resolver for :global/current-user returning the user map and getting the ID from its env, right? If I send {:params {:myid 123}} then I find it somewhere inside the defresolver's env param, right?
@holyjak the params are in the top-level resolver (the first one hit), but you can easily make a pathom plugin that pulls it into the env (see the RAD code, which does that) https://github.com/fulcrologic/fulcro-rad/blob/develop/src/main/com/fulcrologic/rad/pathom.clj#L135.
If you use the ident-based query, then it will trigger the resolver for that ident (i.e. :user/id
) and you wonât need a param.
Using a component for queries is not a hack. Itâs a well-supported pattern for loading data that has no direct UI.
Ok, thank you so much! I feeled as a hack because I see componens primarily as "(visual) things in the UI". I have yet to learn to see it the Fulcro way :) I'll go with the ident query if that is an accepted and also it seems simplest way. Thank you!!!
Iâve thought about making a defquery
macro, but it would just be an alias to defsc
basicallyâŚseems pointless
I had the same thought, that it would be pointless. I have read big chunks of the book but not all - and am already forgetting what I read before đą
normally the query params are only in the entry-pointâs AST, since that is how they are sent
Hi, I have a df/load! ...{ options... }
and in the map of options I have a :post-action
My colleagues weren't sure if that is the right thing to do though as it isn't in the docs.
What is the hook to call on a component when you render it. For example on
defsc-route-target
there is the componentDidMount hook but I on plain defsc what hook is equivalent to that one .. i have tried a few like
:componentDidUpdate
but did not do anything
https://cljdoc.org/d/com.fulcrologic/fulcro/3.1.8/api/com.fulcrologic.fulcro.data-fetch#load!
itâs sort of a shortcut when you feel that a post mutation is overkillâŚI generally donât use it, but it was trivial to provide
thanks @tony.kay I was checking the docstring and I saw the :componentDidUpdate there. For some reason it does not run when I render the component .. but I will try again .. or load stuff before render ..
please remember that Fulcro is not responsible for implementing lifecyclesâŚuse React docs
gotcha .. i understand .. and good pointer to that react doc .. got it đ