Fork me on GitHub
#fulcro
<
2020-07-03
>
Wilson Velez00:07:52

hi, I’m following the videos to learn fulcro 3.0, right now I’ve just finished the video 5: how rendering works

Wilson Velez00:07:27

I downloaded the code for the tag

Wilson Velez00:07:55

and when I tested it with the fulcro version in the example it works as in the video

Wilson Velez00:07:35

but if I upgrade the fulcro version the rendering is “broken” and now it render all the “parents”

Jakub Holý (HolyJak)06:07:29

The default renderer has been changed so that could explain it. It is now the multiple-roots-renderer , which mostly behaves just like the old keyframe-render . Perhaps the older Fulcro version uses the ident-optimized-render , which only renders components with changed data, based on their ident. This has better performance but leads to rendering troubles when Fulcro cannot figure out some dependencies (and does does not re-render something you want it to). For most cases, the multiroot is good enough and simpler.

✔️ 3
Wilson Velez00:07:56

is this something expected from this new versions?

Jakub Holý (HolyJak)07:07:17

@tony.kay regarding the :pre-merge example in http://book.fulcrologic.com/#_initial_state_2 - I like it simplicity but it turns out that if only works if (1) either you use :ui/* for the router property or (2) you make sure to omit Fulcro's not-found from the data tree (otherwise you end up with :my/router :com.fulcrologic.fulcro.algorithms.merge/not-found in the data-tree, which overrides whatever is in the initial state). So perhaps it is better (i.e. less error-prone) to explicitly set the router state:

:pre-merge (fn [{:keys [data-tree]}]
             (assoc data-tree 
               :settings/panes-router 
               (comp/get-initial-state SettingPanesRouter))) 
What do you think? Should I send a PR for this?

zilti11:07:00

...ooh, I have to query for the :db/ident to get the keyword of an enum. 🙂

Jakub Holý (HolyJak)13:07:20

Hello, I am writing a post about possible approaches to error handling in Fulcro. Feedback would be most appreciated! https://gist.github.com/holyjak/a70947d6618c79279c68cc08f948603e @tony.kay I am encountering a Catch-22 problem here. I must add :pc/errorsto my queries (together with Pathom's p/raise-errors) yet I don't need/want to send it to the backend since Pathom would turn all into :p/not-found (and possibly later into actual error maps, if any). I assume I could remove them from the backend query via :global-eql-transfrom . Is this a correct approach? If so - why does RAD use this transform to add :pc/errors to the query ? Thank you!

zilti16:07:56

Is it possible to to a reverse lookup in a defsc query? What my situation is is I have a :notification/triggered-by that points to an :account/id. And I have a :company/primary-account that also points to :account/id. Now I want to, starting from having :notification/id, reach :company/id.

magra16:07:17

If you use datomic you can use :company/_primary-account.

zilti16:07:16

Hmm, I just tried that and got nothing... I guess I could just write a resolver for the reverse case

magra16:07:38

Your pathom resolver has to have a resolver for it.

magra16:07:05

It needs to be mentioned in ::pc/output and be queried.

magra16:07:35

I often replace :user/_company in the resolver with :company/user. That gives me readable backlinks in the normalized db.

zilti16:07:37

I am using Fulcro RAD Datomic, no idea if it does create reverse resolvers. Apparently not, because adding :company/_primary-account returned nothing. Hm. While we're at it, do you know if there's a way to make the ::pc/output being "or" instead of "and"? As in, when I give it #{:company/id :vendor/id} to name an example, that i mean either the first or the latter, instead of both

magra16:07:43

Hmm. Ich glaube Du fragst immer nach beiden und bekommst halt nicht zurück was er nicht findet. Im Output heißt das ja nur, dass er es Dir gibt, nicht, dass er es garantiert.

magra16:07:02

Das ist ein Set, kein AND.

magra16:07:22

Also ein Datomic Pull, kein Datomic Query.

zilti16:07:30

Nein, so wie ich das gesehen habe, benutzt Pathom einen Resolver nur dann, wenn es alles, was ins ::pc/input gehört, hat

zilti16:07:06

Interessanter Sprachenwechsel ^^

magra16:07:36

Jep. In Input schreibst Du Ding/id und im Output Ding/name, Ding/Adresse etc.

magra16:07:07

Ding/id muss er kennen. Und dann schaut er ober dir Ding/Name und Ding/Adresse geben kann.

magra16:07:21

Wenn Du die von Hand schreibst würdest Du ja einen Datomic Pull schreiben.

zilti16:07:31

Genau, aber es gibt wohl keine Möglichkeit, zu sagen, "als Input akzeptiere ich entweder a/id oder b/id"?

magra16:07:29

Das wären zwei Resolver.

magra16:07:47

Du kannst aber einen der beiden so klein schreiben, dass er zum anderen führt.

magra16:07:19

Ansonsten gibt es noch sowas wie "Alias" oder so ähnlich, wenn sich das eine aus dem anderen ableiten läßt.

zilti16:07:54

Hmm okay. Ja, dann gibt's halt mehr als einen 🙂 Danke!

magra16:07:59

Oder es werden drei Resolver, das gemeinsame in einem und zwei kleine, die zum großen überleiten.

zilti16:07:58

Ja, ich habe ein paar Attribute, die ich an mehrere verschiedene "Tabellen" anhängen kann, und ich dachte, ich könnte da vielleicht einen Resolver für alle schreiben ^^ Na, ist ja nicht viel Overhead.

magra17:07:04

Wenn man die Resolver möglichst klein schreibt wiederholt man sich nicht so oft.

magra17:07:43

Ist Geschmackssache.

tony.kay17:07:03

@holyjak I’m kinda busy for the next few days. Ping me again next week.

👍 3
lgessler17:07:40

i'm using slugs instead of ID's in my routes, but a problem I'm running into is that I need to use the ident in my :will-enter , but I don't have it yet because the load (which will give me the ID and other data based on the slug). i could just make the slug my ident, I guess, but is there a way I could handle this without doing that? (posting code as a reply to this)

lgessler17:07:46

here's the code I have so far:

(defsc ProjectDetail
  [this {:project/keys [id name slug] :as props}]
  {:query         (fn [_] [:project/id :project/name :project/slug])
   :route-segment [:project/slug]
   :ident         :project/id
   :will-enter
   (fn [app {:project/keys [slug] :as route-params}]
     ;; we know the slug, but...
     (when slug
       (dr/route-deferred
         ;; we need to put the ident in here and below in the :post-mutation params
         [:project/id ???]
         #(df/load! app [:project/id ???] ProjectDetail
                    {:post-mutation        `dr/target-ready
                     :post-mutation-params {:target [:project/id ???]}}))))}

lgessler21:07:43

the closest I've gotten is reading the ID I need directly from the application db:

(when-let [id (->> app
                                         ::app/state-atom
                                         deref
                                         :project/id
                                         (filter (fn [id {:project/keys [other-slug]}] (= slug)))
                                         first
                                         first)]
This works OK as long as I make sure that data's actually been loaded. But this code kind of stinks, right? is app actually meant to be used this way?

dvingo21:07:25

what if you make the component use :project/slug as the ident?

lgessler21:07:03

i'm reluctant to do it because it'd ruin some symmetries, but in the absence of any other approach that might be the way to go

dvingo21:07:08

you could potentially have this component be "light" and just be used to translate from slug to id and then have it render a component that uses project/id

lgessler22:07:58

hm, interesting idea--so this wrapper would have :project/slug as its ident. but then that would require a separate :project/slug table with a join onto the :project/id table, right?

lgessler22:07:21

(btw your template's awesome, i'm using it on this project 🙂 )

dvingo15:07:27

yea i'm thinking you'd have two tables one indexed by slug and one by id

dvingo15:07:35

woot! glad to hear it!