Fork me on GitHub
Jake Murphy19:07:02

General question about loading data that is never considered stale and that needs to be there before the component mounts... I have been using the following pattern: 1. call a mutation from the component's :will-enter 2. in the mutations' action section, check to see if the data in state, if so, transact dr/target-ready, if not call df/load! with dr/target-ready as a post mutation. This works, however, I would like df/load! itself to be 'smart enough' to check to see if it needs to make the network request before doing so. Is there a suggested way to implement this behavior: a short-circuit of the network request from calls to df/load! That would make the code very simple.

Jakub Holý (HolyJak)20:07:30

I would think this is app-specific (when is data to be considered stale?) and there is not built-in way to do it. But you could construct your own variant of df/load with the requisite behavior. Not sure that would make your code simpler. If you go this way, I would be happy to see the code 🙂

Jake Murphy21:07:40

Gotcha, thanks for letting me know there isn't yet a way to to do this. If I like what I come up with, I will post it here.

🙏 1

There is a namespace (alpha) in Fulcro for doing this…well, in a way: See com.fulcrologic.fulcro.offline.load-cache but perhaps that isn’t quite what you meant (that would let you cache data over multiple sessions).


The basic idea of the offline support is just that: be able to load stuff when there is no network, but only if it’s been seen before (e.g. get me the most recent version of X). The durable mutation support goes the other way: save idempotent mutations for later sending to the server when back online.

Jakub Holý (HolyJak)21:07:58

So Jake could use com.fulcrologic.fulcro.offline.load-cache/load-eagerly! which would return at once if the value is already cached - but contrary to what he currently does, it would still call the server to refresh the cache. Right?


right. It’s configurable and you could also just treat it as an example of how you can muck with the internals to do whatever you like.

👍 1
Jake Murphy14:07:31

(defmutation load-if [{:keys [load? load-args] :as params}] (action [{:keys [state app] :as env}] (if (load? state params) (apply df/load! (into [app] load-args)) (let [{:keys [post-mutation post-mutation-params post-action]} (last load-args)] (when post-mutation (comp/transact! app [(post-mutation (or post-mutation-params {}))]))` (when (fn? post-action) (post-action env)))))) (defn load-if! ([app server-property-or-ident class-or-factory] (load-if! app server-property-or-ident class-or-factory {})) ([app server-property-or-ident class-or-factory config] (let [{:keys [load? routing-ident]} config load-config (cond-> (dissoc config :load? :routing-ident) routing-ident (assoc :post-mutation dr/target-ready` :post-mutation-params {:target routing-ident}))] (comp/transact! app [(load-if {:load? (or load? (constantly true) :load-args [server-property-or-ident class-or-factory load-config]})]))))

Jake Murphy14:07:48

Thank you for the suggestions. I'm not sure I need to go the offline route at this point, but I may need it in the future.


Is there a low friction way to go about implementing localized dom in the rad template?


I think that's localization and not localized dom. A bit of term overloading. localized dom is, If I understand correctly, for localizing things like css with components.


specifically I'm referring to the ns fulcro.client.localized-dom


presently rad uses com.fulcrologic.fulcro.dom(-server) namespaces (as well as corresponding semantic ui ns s)


just realized I inadvertently was on an old fulcro docs


Now I'm looking at the proper docs and they are pointing me to fulcro-garden-css and I'm getting the same instructions. So I am back to lost again on how to have localized css in the rad project. The whole 'usage' section has me a bit confused. So I'm not sure if I'm just doing it wrong or if RAD requires a different approach for colocated css

Jakub Holý (HolyJak)22:07:11

Does (locdom/div {:classes [header-logo]} "test") - ie both with props and a child - work? IMO localized-dom should work with RAD in the same way as it does with non-rad. Perhaps try to get it working in a plain fulcro app first?


Realized my errors. Thanks for trying to help!

👍 1