Fork me on GitHub
#fulcro
<
2019-02-12
>
eoliphant16:02:03

hey @tony.kay, quick question. a follow on to my last, i have access to the reconciler in my resolver now, but I’m not clear on how to issue an arbitrary query. so that I can do something like (let [token (??? resolver [[:sec-token '_]])]?

hmaurer16:02:57

@eoliphant get the state atom and do a get on that?

hmaurer16:02:32

(prim/app-state reconciler) by the way 🙂

hmaurer16:02:29

You can also issue queries using db->tree (https://github.com/fulcrologic/fulcro/blob/bae67e67abe1b15c74a10768be53c3d83fcdc411/src/main/fulcro/client/primitives.cljc#L1335) but getting the app state and working with it directly seems better for your use-case

eoliphant16:02:00

yeah, for this at least, I know exactly what I want

hmaurer16:02:35

are you running Pathom on the client by the way @eoliphant?

eoliphant16:02:16

yeah, have a few unfortunate rest apis

eoliphant16:02:19

we have to pull in

hmaurer16:02:24

ah fair 🙂

eoliphant16:02:27

this is actually inside the resolver for one of them

eoliphant16:02:41

where we need to slap the security token on the api

hmaurer16:02:56

it’s quite neat that you can wrap them in pathom resolvers and then have a nice interface for Fulcro to work with

eoliphant16:02:38

yeah that’s a pretty killer feature

eoliphant16:02:53

the ‘extra’ remotes

hmaurer16:02:55

also note that you can also pass an atom to :initial-state when building the Fulcro client

hmaurer16:02:06

so (I think) what you could have done is set up a state atom, pass it to initial state

eoliphant16:02:08

yeah this is more of a pain

hmaurer16:02:12

then just reference that atom in your resolvers

eoliphant16:02:27

because, we have to handle the token possibly being refreshed etc

hmaurer16:02:30

(but you would need to initialise that atom manually)

eoliphant16:02:00

i see what you’re saying

eoliphant16:02:21

may try that on the next pass

hmaurer16:02:39

By the way I am very much a beginner with Fulcro as well so don’t take anything I say as gospel 😛

eoliphant16:02:46

i’m actually 50/50 about the suitability of keeping that token in the app db at all

eoliphant16:02:20

since the security lib, we’re using already maintains it in local storage or something

hmaurer16:02:21

I guess it’s fine in the app db if it doesn’t need to be persisted

hmaurer16:02:33

if it does, local storage, although some people would argue that’s unsafe

hmaurer16:02:39

(and that you should use cookies instead)

hmaurer16:02:36

if it’s already in local storage, why put it in the app db though?

eoliphant16:02:30

hey quick question Im seeing that (:state reconciler) gives me just the app db, and (prim/app-state reconciler) seems to return it plus a bunch of other stuff

eoliphant16:02:08

yeah, that’s why I’m back and forth about it, probably needless complexity. Since the js lib, that handles this is already managing that

hmaurer16:02:43

I’m not sure what :state on the reconciler corresponds to

eoliphant16:02:46

there’s other info, about the user that might be useful to stick in there, but the token itself, probably not so much so

hmaurer16:02:50

but prim/app-state gets [:config :state]

hmaurer16:02:43

in my application I am storing the security token in an https-only cookie. So I don’t have to care about it at all; it’s passed automatically with requests (and stored)

hmaurer16:02:55

but for you that’s obviously not an option since you are working with an existing API

hmaurer16:02:14

if there are no other factors at play I would just leave it in local storage and not pull it in the app db

hmaurer16:02:21

seems unecessary

eoliphant16:02:55

yeah that’s what I’m leaning towards

eoliphant16:02:18

we’re using cljs-http which i like because it’s all core.async’y

eoliphant16:02:35

but it doens’t seem to support interceptors, which would be nice

eoliphant16:02:33

since we basically want to: add the token, try the request, if it 401's refresh the token, then retry etc. each time so looking into that as well, and as we talk about it more definitely going to just rip it out at this point lol

hmaurer16:02:52

lol yeah. Well on my application I use the built-in http fulcro remote (since my API is fulcro-compatible). I added a middleware which looks for 401s and if so, refreshes the application (which redirects to the login page)

hmaurer16:02:55

crude, but it works

hmaurer17:02:02

I could have attempted to refreshed the token there as well

hmaurer17:02:27

it’s odd cljs-http doesn’t support interceptors though. Surely you can add a “middleware” step somehow?

hmaurer17:02:31

(I haven’t used it)

eoliphant17:02:50

yeah i’ve been looking at it

eoliphant17:02:08

would be a useful pr lol

hmaurer18:02:30

@eoliphant are you writing a novel? 😄

😂 5
eoliphant18:02:15

hey I have a question. I have a requriment for some ‘dynamic’ forms. where as opposed to say this from the form state demo

(defsc PhoneForm [this {:keys [:db/id ::phone-type root/dropdown] :as props}]
  {:query       [:db/id ::phone-type ::phone-number
                 {[:root/dropdown '_] (prim/get-query bs/Dropdown)} ;reusable dropdown
                 fs/form-config-join]
   :form-fields #{::phone-number ::phone-type}
   :ident       [:phone/by-id :db/id]}
  (dom/div :.form
    (input-with-label this ::phone-number "Phone:" "10-digit phone number is required.")
    (input-with-label this ::phone-type "Type:" ""
...
I can have some sort of DynForm component or just a builder macro, that would read a form def (maybe returned from the server) perhaps like this:
{:form/name ..
 :form/id :phone/id
 :fields [{:key :phone/number :type :text :validations [....]} ...] 
I’m trying to get my head around how this could get wired into the app db properly. A DynForm SC, could maybe use a dynamic query at the top level, but not sure if the form state stuff itself can be handled that way. If say created the entire defsc dynamically, not sure how it’s containing SC would keep things straight

eoliphant18:02:51

lol I’d started typing this, then had a person in my office like every 5 mins lol

exit222:02:45

what would be the ident for this? I’m getting a warning I need one

exit222:02:17

(defsc FormProto [this {:keys [which-tab]}]
  {:query [:which-tab]
   :initial-state {:which-tab :form-proto}}
  (dom/div "FormProto"))

currentoor22:02:09

@njj are you using that inside a router?

currentoor22:02:27

if not, you can make an ident up

currentoor22:02:57

something like :ident (fn [] [:COMPONENT/by-id ::form-proto]) would work