Fork me on GitHub

I have a working resolver (similar to defquery-root) and working query: [(:find/device {:rgt "123"})

(pc/defresolver device-resolver [env params]
  {::pc/output [:find/device]}
  (let [rgt (get-in env [:ast :params :rgt])]
    {:find/device (find-device-by-rgt rgt)}))
;; query
[(:find/device {:rgt "123"})]
;; result
 {:device/rgt "ZZ",
  :device/id 123}}
How to fetch the result? df/load! ? something low level? I would like to fetch the data and then use merge/merge-component!

Björn Ebbinghaus13:05:41

I would do it like this:

(pc/defresolver device-rgt->id-resolver [env {rgt :device/rgt}]
  {::pc/input #{:device/rgt}
   ::pc/output [:device/id]}
  (find-device-by-rgt rgt)))

(defsc Device [_ _]
  {:query [:device/rgt :device/id]
   :dent :device/id}) ; or rgt

(df/load! app-or-comp [:device/rgt "ZZ"] Device)
This will handle the load and the merge. You can decide where to put it in your client db with :target or use :post-mutation if you want to do something more complicated.


Thanks, But how to call the resolver for autocomplete? ?

Björn Ebbinghaus13:05:14

You can load on a global attribute (`:find/device`) and load! takes a params map.

(df/load! app-or-comp :find/device Device {:params {:rgt "123"}})


@U4VT24ZM3 Thank you, it works. But now I have the latest resolver. Which is returning list of maps, and there is no unique key. there could be some duplicates. So I am not sure how to load the data into client database.

(pc/defresolver spds-resolver [env params]
  {::pc/output [:find/spds]}
  (let [device-id (get-in env [:ast :params :device/id])]
    {:find/spds (filter-spds (stash-data device-id))}))

  {:find/spds [{:spds/ts "20210514154820", :spds/cid "4"}
 {:spds/ts "20210514153931", :spds/cid "3"}
 {:spds/ts "20210514153931", :spds/cid "3"}
 {:spds/ts "20210514153436", :spds/cid "1"}]}

Björn Ebbinghaus15:05:28

You don't need an ident.

Björn Ebbinghaus15:05:18

(defsc Spd [_ _] 
  {:query [:spds/ts :spds/cid]})

(df/load! app-or-comp :find/spds Spd {:params {:device/id 42}})

(:find/spds (app/current-state app-or-comp))
; => The data you are looking for 

Björn Ebbinghaus15:05:13

Or put it wherever with :target

{:params {:device/id 42}
 :target [:my-path-somewhere :in-the-db]}

(get-in (app/current-state app-or-comp) [:my-path-somewhere :in-the-db]) ; => The data you are looking for 


@U4VT24ZM3 Thank you very much

Jakub Holý (HolyJak)13:05:13

It's work of @U0G3C3USJ, I just link to it :)


But the link is helpful to me. Thanks @U0G3C3USJ!

👍 3

@holyjak For a beginner without any experience with React, to be productive with Fulcro, do you think if I should really take the detour to do referred in ? Given my pleasant experience of following the link to EQL Tutorial, I feel that it might be a prudent idea to be eventually more effective.


If you don't know how react should be used, you are bound to run into problems when working with any system that uses react underneath, fulcro included.


But if by experience you meant you haven't used react though you know it in theory, then I'd say that there's not that much to be gained with doing any exercises or such


Then again I used react before I went with reagent and reframe, and now fulcro, so it's just speculation on my part


Thanks @U8ZQ1J1RR for sharing!

Jakub Holý (HolyJak)09:05:43

You don't need to do the tutorial but you need to understand the basics of React. This one seemed as a good entry into that in the limited time I spent looking for something. I'm sure there is an intro more suitable for our unique needs somewhere.. Let me look at this one again..

Jakub Holý (HolyJak)09:05:20

I think the idea was to just read through the part. Does that work for you? Or should we look for something better?

Jakub Holý (HolyJak)16:05:23

I struggle to find the right intro into react for a Fulcro person. The best one I found so far is perhaps

Jakub Holý (HolyJak)16:05:07

@U2QGRCMSM I have updated the part about React under I hope it is more useful now! (should be deployed within 5 min)

👍 2
🙏 2

@holyjak Thanks! I'm reading your Minimalist Tutorial the second time. I found that I have missed so much in the first reading. Thanks again!

❤️ 2