Fork me on GitHub
Chris Rosengren03:04:39

Hi, right now each of my components is backed by an entity in datomic so I can easily d/pull on the server to get the data I want without modifying the query, this breaks as soon as I put idents in the queries, is there a standard way of solving this? Otherwise do I need to recursively go through the query on the server and pull out idents before passing it to d/pull ?


@christopher.rosengren typically you won’t have idents in queries you send to the server…the most common case to use them is when you want to anchor a query in a load (load [:thing 3] Thing), but that hits defquery-entity for that particular case. If you actually need to process queries that have an ident in the middle of the graph, then you are going to want a parser. I recommend pathom

Chris Rosengren06:04:43

If in the action of a defmutation, I have a swap! state followed by a df/load, should I have :refresh keys in the load config AND in the defmutation (refresh [environment]) part?


@christopher.rosengren I usually try it out until it works. For most cases since I'm updating data that the component queries there;s no need for refresh keys.


@christopher.rosengren Have you seen the Developer’s Guide? Load should not be used in muations…`load-action` is there for that purpose. perhaps you meant that and are asking about refresh. If you’ve used load-action (with remote-load), then either should work.


Hi! A quick question - what is the preferred way to run loads with defined interval? Right now I have the following in the started-callback (where load-data just calls data-fetch/load):

(fn [app]
  (load-data app)
  (js/setInterval #(load-data app) 30000))
Is there a better/more idiomatic way?


@piotrek that seems totally fine to me. more sophistication only if you go down to SSE or Websockets, but that's a different beast

🙏 4

One more question - I need to load a list of items (and I trigger loading in started callback) and I would like to show different UI when no data load has been loaded yet and when an empty list of items has been loaded (and the loading can happen again from interal). What is the suggested way to differentiate between “list of items not loaded yet” and “loaded empty list”?


One approch could be setting the initial value in initial-state to nil, then after load the value dhould be [] so you can treat them differently in the ui.


That’s what I’m doing right now - thanks @claudiu. I was wondering how others are handling this


Using (fnil conj []) in your update function - examples in the book.


Thanks @cjmurphy - I will have a look

🙂 4

One more question about loading and UI 🙂. When my app starts I’m triggering a load and I’m showing a big loader on the whole screen (it’s shown when :ui/loading-data is present and loaded items is nil as discussed above). However, there is a flicker as first :ui/loading-data is not present until started-callback triggers the load so initially there is a UI that is shown when :ui/loading-data is absent and items is nil. Is there any way to prevent that flicker?


Maybe I should pass :initial-state {:ui/loading-data true} to new-fulcro-client?


Oh, I can just add :ui/loading-data to my root component’s initial-state 🙂


set-value! or toggle! require the component where they are used to have an ident - I wanted to use them in my root component for updating global :ui/... key in the db and it didn’t work. Are there any shorter ways to set global db key than writing a client-only mutation?


I don't think so. Only way to affect state is by mutations. Good not to do too much in the Root and get to the real root of the application, which will be a component that does have an ident, as quickly as possible. Top level keys not so great IMHO. Instead if you need something that is 'one of' have an ident with a static id part, for instance :UI is used in some of the demo applications, so [:start-panel/by-id "main"].


(I used "main" rather than :UI because slack was giving me emojis)


Thanks @cjmurphy. I need to review my code and maybe move some parts out of the root component.