Fork me on GitHub
#fulcro
<
2020-02-19
>
tony.kay01:02:58

RAD progress: I got quite a bit of File Upload working in RAD today. It needs a lot of refinement, but it already allows for selecting a file, uploading it sideband while they continue to edit the form, tracking upload progress, and fixing up the form values on save.

🚀 56
looprecur16:02:51

Question: why in the live routing example (#37 in developer's guide) do you not need to use an element factory on Main and Settings? I see that they are not composed into a tree in code explicitly so does the router do this behind the scenes?

tony.kay16:02:04

@looprecur you don’t need to make factories…the router makes its own…just an oversight in book

tony.kay16:02:46

I have a smart template in my editor that makes a new defsc and factory in code if I just type class name…just forgot to delete the factory.

looprecur17:02:53

Okay, thanks!

thosmos20:02:41

Is :will-enter a good place to check for an active session, and is this a reasonable way to do it?

{:will-enter (fn [app {:keys [id] :as params}]
               (let [editor-ident [:component/id :editor]
                     session-valid? (get-in (fapp/current-state app) [:component/id :session :session/valid?])]
                 (if session-valid?
                   (dr/route-deferred editor-ident ...)
                   (dr/route-deferred editor-ident
                     #(do
                        (dr/change-route app ["main"])
                        (dr/target-ready! app editor-ident))))))}
It seems like this would need to be done for every route target that needs auth …

tony.kay20:02:00

Remember that will-enter can be called multiple times during route resolution (search for matching route)

tony.kay20:02:14

perhaps not the best name…should prob be called “might-enter”

tony.kay20:02:50

so as long as the code is idempotent in nature it is prob ok

tony.kay20:02:22

I would tend to put security about session in my own nav-to kind of function. If you want to co-locate data/lambdas related to it on targets, then just add that to the options map of the compinent under new nsed keys

thosmos20:02:31

well it’s just doing a read on the global app state … 3 times … maybe it’d be better to check in the URL parser before change-route even gets called the first time …

tony.kay20:02:02

yeah, I guess if you’re coming from strings it might make sense to use will-enter now that you say that

thosmos20:02:04

yeah, the only thing before :will-enter is my pushy URL parse code

thosmos20:02:46

Is there a way to look up a component based on the route str vector? dr/route-target? Yes, this works from my URL parser to get the component options and I’ll add an entry to check if it needs auth:

(comp/component-options 
  (:target
    (dr/route-target
      (comp/registry-key->class :riverdb.ui.root/TopRouter)
      ["sitevisit" "edit" "123"])))

thosmos22:02:26

oh no actually that just gets the top level route target …

cjmurphy22:02:39

@tony.kay Is the function delta->datomic-txn supposed to handle Fulcro tempids well, or is that something that might need to be improved, or am I thinking about it the wrong way? I can come up with a specific failing example, just wanted to ask the general question first.

thosmos22:02:04

from what I could tell reading that fn a week or two ago is that it only handles tempids that are of the form :entity.type/id and replaces it with UUIDs. This didn’t work for me because I use :db/id for my tempids and must parse and replace with longs.

tony.kay22:02:42

you talking RAD???

thosmos22:02:05

oh right sorry and I’m not using RAD

tony.kay22:02:42

that is definitely not refined yet. RAD datomic adapter is currently only implemented/tested if you use user-domain UUID for ids…but I do plan on making an option for dealing with plain :db/id as the ID of a thing.

tony.kay22:02:05

but in the case you’re using the supported ID type, then it does handle tempids. There is more middleware to install…file uploads needs to be able to handle tempids, etc.

cjmurphy22:02:59

Yes I'm talking RAD. The datomic RAD driver is where that function comes from. You give it a forms diff that has before and after. What I give it has (tempid/tempid)-s in it (Fulcro tempids).

cjmurphy22:02:16

(Give it result of fs/dirty-fields).

tony.kay22:02:08

Yes, but it assumes something like :account/id is a reified field on your entity, not :db/id

tony.kay22:02:26

that’s the option that needs added to the adapter: something that tells it IDs map to db/id

tony.kay22:02:59

also, much of RAD currently assumes UUIDs, so there’s some work to do. Most SQL dbs are also going to want to use integer IDs

tony.kay22:02:29

My personal project uses user-space UUIDs, so those are going to get preferential treatment (from me at least)

cjmurphy22:02:05

I've converted to using uuids (so idents always /id) completely on the client. No :db/id there at all. Wanting to go for the most recommended way always! But I still use tempids as per the recommendation from you and @thosmos as it happens.

cjmurphy22:02:58

The recommendation was for the server to just unwrap them when doing tempid remapping.

tony.kay22:02:01

RAD uses tempids, so not sure what your prob is

tony.kay22:02:33

or wait…does that happen one layer above…

tony.kay22:02:43

might be one layer above if you’re using the low-level fn directly

tony.kay22:02:47

use the source 🙂

cjmurphy22:02:52

Well that answers my question. I'll look some deeper. Never found that function being called from anywhere when I looked, but that must have been a bad search on my part.

tony.kay22:02:26

each db adapter defines a handler. That handler in datomic.clj calls that fn

tony.kay22:02:10

line 170 is the fn, 181 is the call

cjmurphy22:02:33

Thanks, will look..

tony.kay22:02:59

and yes, that’s where the tempid magic is happening

tony.kay22:02:31

line 180 transforms the delta to use squuids

cjmurphy22:02:25

Got it: form-delta (sp/transform (sp/walker tempid/tempid?) fulcro-tempid->real-id form-delta)

tony.kay22:02:37

@thosmos will proposed-new-path work for you?

tony.kay22:02:15

it returns idents of targets…you could use that as a starting pt to make whet you need

tony.kay22:02:57

the logic in change-route-relative is what you really want: find the target…could factor that out

thosmos22:02:34

I’ll take a crack at factoring out the find algo

tony.kay22:02:16

There is a TODO in that ns…a lot of that logic is duplicated in two places already I think

tony.kay22:02:33

and would be nice as a top-level fn…just didn’t want to fiddle with it and break things 😛

thosmos22:02:43

yeah I saw that message. if I get something working I’ll maybe see if it works for those

tony.kay22:02:20

guess I have enough running on it now and tests that I could fully test it and feel comfortable

thosmos23:02:52

just looking at the fns: dr/proposed-new-path, dr/signal-router-leaving, and dr/change-route-relative, it appears that the latter 2 call and use variations of the first. So it seems like the first could generate enough metadata on the path to allow the other two to use its output and minimize the duplication?

tony.kay00:02:49

seems reasonable

thosmos00:02:55

I don’t have the brainwidth for this right now