This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-03
Channels
- # announcements (4)
- # beginners (68)
- # boot (3)
- # business (20)
- # cider (39)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (12)
- # clojure (122)
- # clojure-brasil (2)
- # clojure-italy (7)
- # clojure-nl (5)
- # clojure-spec (60)
- # clojure-uk (41)
- # clojurescript (67)
- # cursive (7)
- # datomic (13)
- # emacs (6)
- # figwheel-main (18)
- # fulcro (40)
- # garden (3)
- # graphql (2)
- # hyperfiddle (4)
- # jobs-discuss (10)
- # lein-figwheel (5)
- # leiningen (12)
- # luminus (6)
- # mount (3)
- # off-topic (52)
- # portkey (2)
- # re-frame (1)
- # reagent (6)
- # reitit (24)
- # shadow-cljs (15)
- # sql (3)
- # tools-deps (12)
Hi, is there a canonical way to fetch data (like data-fetch/load
) only if it not already in local state? We want to use this to refer to (maybe) already loaded data entries
@twan In df/load
you have the :without
http://book.fulcrologic.com/#_pruning_the_query . For more generic stuff there is :update-query
https://cljdoc.xyz/d/fulcrologic/fulcro/2.6.5/api/fulcro.client.data-fetch#load .
as far as I know, there is no magic cache stuff implemented in fulcro. You have to look at the state and decide if some stuff is already loaded and tell df/load to elide it from the query or not issue the df/load at all.
@twan you can write one yourself using :update-query
, since most of the time you will have the ident of the entity you are going to load from, you can use that to get the current data on the DB and prune those parts out of query
I don't think he's asking about query pruning... @twan I think perhaps the answer to your question is: yes, write a mutation (i typically name it something like ensure-thing-loaded) which: 1. Looks in app state. If the thing is not found, then issues df/load-action. 2. Always calls df/remote-load in the remote side of the mutation (which is a noop if there was no load action)
Thank you very much, also @claudiu and @wilkerlucio
Such a mutation is then safe to put in places like react lifecycle methods, or combined with mutations that do routing
(defmutation ensure-dropdown-options-loaded [_]
(action [{:keys [state] :as env}]
(let [options (get-in @state [:path :where :options :live])]
(when-not (seq options)
(df/load-action env ...))))
(remote [env]
(df/remote-load env)))
How can I access the form-fields
given a reference to a component?
(Use case: adding a new model to a form in a generic way)
Right now the only way to do this is setting the initial-state with the prop names I need in order to set up an empty model by using (prim/props component)
@pvillegas12 in both kinds of form support the “form fields” current values are just your component’s fields…nothing special. Access them as you would without form support
Given
(defsc PersonForm [this props]
{:query [:db/id :person/name {:person/phone-numbers (prim/get-query PhoneForm)}
fs/form-config-join]
:ident [:person/by-id :db/id]
:form-fields #{:person/name :person/phone-numbers}}
...)
how can I do something like (get-form-fields PersonForm) ; => #{:person/name ... }
I want to generically populate a form without having a hard wired map like
(def person-tree
{ :db/id (prim/tempid)
:person/name "Joe"
:person/phone-numbers [{:db/id (prim/tempid) :phone/number "555-1212"}]})
“populate a form” from a load, a data generator, or what? The basic approach is as documented here http://book.fulcrologic.com/#_initializing_a_tree_of_data
you have to put the props in app state, as you normally would no matter what, and also run a add-form-config on it.
You can do that all in a single custom mutation with the helper versions of merge-component and add-form-config*
Yes, that’s what I have right now but for a specific model
or if you’re doing a load, then you can do a post mutation that just runs the add-form-config* helper on it
I want to infer the attributes a form needs from a stateful component
and do something like (zipmap model-attributes (repeat nil))
so you can just call the protocol to get the declared fields, if that’s what you mean
yes, I think that’s what I need
what is the way to call it?
(form-fields this)
should do it…I think it is also a static protocol, so you can call it with the class too
ah, the prim/get-ident
fn only works when props are given to a component? 😛
get-ident
works on instaces OR classes with props…needs props one way or the other to calculate ID 🙂
or perhaps you’re asking something else…I think it is pretty well covered in the book, isn’t it?
@wilkerlucio can the inspector work with advanced compilation on?
I think so, you just have to ensure the preload is setup on the adv build, usually the compiler takes those out (shadow or figwheel), so you might have to call the initialization yourself
i was thinking it might be useful to have an alternative URL in prod that works with the inspector for debugging certain kinds of issues, i don’t care if that build gets bloated
you just have to call this function: https://github.com/fulcrologic/fulcro-inspect/blob/master/src/client/fulcro/inspect/preload.cljs#L4
cool thanks
and make sure you call it before any apps are initialized
right
I think it's not going to bloat, the client is very thin these days (most heavy things were move to the extension)
the main reason to don't do it is because of the overhead you have to encode states to send to inspect, but bundle size addition is probably negligible
yeah makes sense
either way, it’s fine that my debug build is a little slow or worse in some types of performance
Thank you very much, also @claudiu and @wilkerlucio