fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
janezj 2021-05-14T12:58:49.344600Z

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
{:find/device
 {: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!

janezj 2021-05-15T12:35:39.356700Z

@mroerni Thank you very much

Björn Ebbinghaus 2021-05-14T13:18:41.345100Z

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.

janezj 2021-05-14T13:21:58.346700Z

Thanks, But how to call the resolver for autocomplete? https://book.fulcrologic.com/#_the_server_query ?

Jakub Holý 2021-05-14T13:23:13.347200Z

It's work of @alex-eberts, I just link to it :)

yubrshen 2021-05-14T13:28:33.347400Z

But the link is helpful to me. Thanks @alex-eberts!

1👍
Björn Ebbinghaus 2021-05-14T13:30:14.348700Z

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"}})

yubrshen 2021-05-14T13:32:36.350300Z

@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 https://reactjs.org/tutorial/tutorial.html referred in https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/#_prerequisities ? 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.

Jakub Holý 2021-05-15T09:10:43.356100Z

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ý 2021-05-15T09:30:20.356300Z

I think the idea was to just read through the https://reactjs.org/tutorial/tutorial.html#overview part. Does that work for you? Or should we look for something better?

Jakub Holý 2021-05-15T16:10:23.359600Z

I struggle to find the right intro into react for a Fulcro person. The best one I found so far is perhaps https://dzone.com/articles/fun-with-react-a-quick-overview

Jakub Holý 2021-05-15T16:25:07.360Z

@yubrshen I have updated the part about React under https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/index.html#_prerequisities I hope it is more useful now! (should be deployed within 5 min)

1👍1🙏
yubrshen 2021-05-15T16:39:52.360600Z

@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!

1❤️
janezj 2021-05-14T14:51:53.350800Z

@mroerni 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 Ebbinghaus 2021-05-14T15:13:28.351Z

You don't need an ident.

1✅
Björn Ebbinghaus 2021-05-14T15:16:18.351200Z

(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 Ebbinghaus 2021-05-14T15:24:13.351400Z

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 

Hukka 2021-05-14T19:07:36.351800Z

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.

Hukka 2021-05-14T19:08:31.352Z

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

Hukka 2021-05-14T19:09:15.352200Z

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