Fork me on GitHub
#fulcro
<
2019-02-22
>
pvillegas1203:02:21

Is there any support for a URL such as user/id/products with the dynamic routing?

tony.kay03:02:20

@pvillegas12 of course…do the docs not make it clear?

pvillegas1203:02:42

trying to get it to work right now

pvillegas1203:02:13

using #(dr/change-route-relative this UserDetails ["products"]) but in the will-enter I’m not receiving the user id

pvillegas1203:02:05

tried doing (dr/change-route this ["user" id "products"]) too

pvillegas1203:02:36

But it chops off products in this case for some reason (loooking at the fulcro db for routing)

tony.kay03:02:44

Fulcro 2.8.3 on Clojars, and Incubator 0.0.29. The Fulcro fix is a long-overdue fix to fulcro logging. The incubator fix adds debug logging (which requires 2.8.3 of Fulcro) to state machines so you can see how they are working. Incubator also has deferred routing fixes for dynamic routing. See the docs, as the API had to include a new method to accomplish it properly.

tony.kay03:02:20

@pvillegas12 what is your prefix defined as for the route target?

pvillegas1203:02:47

:route-segment (fn [] ["user" :user-id])

tony.kay03:02:00

ok, so that one can consume /user/222

tony.kay03:02:09

then you have a nested router underneath there?

tony.kay03:02:21

with prefix [“products”]

pvillegas1203:02:46

the route params are the ones I’m not receiving

tony.kay03:02:49

I don’t think I’ve tried that particular combo, but I expect it to work

pvillegas1203:02:51

should I upgrade to the latest fulcro?

tony.kay03:02:00

the upgrades don’t affect this for sure

tony.kay03:02:12

well, depending on your deferral of routing

tony.kay03:02:43

You may have discovered another bug….darn-it, I just finished fixing the last one you found 😉

pvillegas1203:02:51

should I be doing the dr/change-route-relative or dr/change-route?

tony.kay03:02:00

depends on what you pass

pvillegas1203:02:06

both should work right?

tony.kay03:02:16

right, but arguments have to vary properly

pvillegas1203:02:24

either ["user" id "products"] or simply ["products"] with the right prefix class

tony.kay03:02:35

the latter should work if you pass the router whose targets include one that accepts “products”, yes

tony.kay03:02:57

The former would have to be sent to the router that targets the prefix target accepting “user”

tony.kay03:02:18

Technically it should work if passed something “in between” the two as well

tony.kay03:02:34

I have to go to dinner…back later

👍 5
tony.kay03:02:09

If you upgrade to the latest versions, you’ll be able to see a LOT more info with debug logging in console

tony.kay03:02:19

it’ll tell you what’s going on in the state machines,e tc.

pvillegas1203:02:20

I’ll do that right now

pvillegas1204:02:34

After updating getting more debugging info, looks like it does the RootRouter transition but

pvillegas1204:02:09

Attempt to get an ASM path [:fulcro.incubator.ui-state-machines/local-storage :pending-path-segment] for a state machine that is not in Fulcro state. ASM ID:  :dataico.ui.user.details/UserRouter
it complains on the UserRouter

tony.kay04:02:44

you upgraded incubator as well?

tony.kay04:02:52

that warning should no longer be there

tony.kay04:02:57

I’m done for tonight…basically when you route it calls begin on the state machine it matches. Perhaps for some reason it isn’t ok with the id-based target

pvillegas1204:02:24

thanks for looking into it 🙂

tony.kay04:02:34

I may have time to look at it more tomorrow. The source isn’t that large if you wanted to clone incubator and do deps :local/root and debug it further

👍 5
nha10:02:02

in https://wilkerlucio.github.io/pathom/#_parameters queries like:

[(::instruments {:sort :instrument/brand})]
  
have to be quoted in fulcro right?
(defsc  MyComp [this props]
  {:query ['(::instruments {:sort :instrument/brand})]}
  )
  
also is (-> env :ast :params) correct? I have to do (-> env :ast :children first :params) (my query shows as a :type :join, so I may be doing something wrong)

nha11:02:28

ah - probably because I have a {:all-instruments (prim/getQuery MyComp)} in my root - not sure how to avoid that

nha11:02:13

because if I remove :all-instruments in my root query - how do I: :started-callback (fn [dashboard] (df/load dashboard :all-instruments MyComp))?

eoliphant14:02:52

@nha I think it's just a matter of using one or the other consistently

5
tony.kay16:02:52

@nha if you component has an ident, you can use the ident instead of a keyword to load a specific instance.

tony.kay16:02:48

but if you intend to load “many” like your q implies, then why wouldn’t you want that join?

nha17:02:31

Right that’s possible too - not very confident in the way of writing queries yet. the Pathom docs did help a lot though. I wish there was a way to “play” in the fulcro docs like in the pathom ones - particularly around the queries/idents/normalisation as I feel like I have to re-learn it every time.

tony.kay18:02:47

You can “play” in fulcro inspect

tony.kay18:02:56

The query tab has autocomplete, etc. (if you load indexes with the button next to run)

tony.kay17:02:47

remember docker additions changed db configs a bit

tony.kay17:02:53

just merged to develop

pvillegas1217:02:40

@tony.kay got the routing working finally, traced down the bug in my code 🙂

pvillegas1217:02:57

I have the following routing structure

CompanyDetails [:company/by-id :company-id]
|                           \
UserDashboard                InvoiceDashboard
How can I pass the company information to both of these sub-routes?

pvillegas1217:02:42

UserDashboard and InvoiceDashboard are defined in the CompanyRouter, not the RootRouter as CompanyDetails, so I don’t have access to the router param for the :company-id

tony.kay17:02:13

@pvillegas12 you mean you want to use the current route to figure out the new one?

tony.kay17:02:15

1 - Use relative routing to avoid needing to know it 2 - Read the current route and pull it out of the path segments 3 - Remember the value in a well-known location in app state and use abs change route (e.g. when you originally set the route, remember it)

pvillegas1218:02:37

What I would like is to pass company as props to my UserDashboard and InvoiceDashboard

pvillegas1218:02:04

basically, CompanyDetails makes the query to the server, and switches UI for both dashboards already having the data

pvillegas1218:02:35

I’m having props being empty in my defsc-route-target declarations of course, because my query lives in the parent

tony.kay18:02:41

Ah, interesting use-case…So, there is a router in-between

tony.kay18:02:50

and you’d like to send computed through it…that seems a valid use-case

tony.kay18:02:53

also should be easy to proxy computed through…so if you pass computed to the router, it passes it to the target

tony.kay18:02:15

minor change to line 490 in dynamic_routing

pvillegas1218:02:13

I’ll try the computed approach

tony.kay18:02:22

as in a PR?

tony.kay18:02:25

it can’t do it yet

tony.kay18:02:48

I’ll send a snapshot…just a sec

tony.kay18:02:41

@pvillegas12 0.0.30-SNAPSHOT on clojars

tony.kay18:02:53

proxies computed through the router

tony.kay18:02:30

tested and released

tony.kay18:02:54

@pvillegas12 Incubator 0.0.30 is on clojars, and includes computed props proxying through the router.

👍 5
pvillegas1218:02:20

Just to clarify, this means something like

(ui-router (prim/computed router {:my-prop my-prop}))`
and then
(defsc-route-target UserDashboard [this _ {:keys [my-prop]}]
...
)

tony.kay18:02:03

the router_ws in incubator’s workspaces does just that to verify it works (on User)

pvillegas1219:02:41

hmm, not getting the computed, is it necessary to use dr/route-deferred?

pvillegas1219:02:57

(defsc-route-target CompanyDetails
  [this {:keys [company/pos-systems company-router] :as props}]
  {:ident           [:company/by-id :db/id]
   :query           [:db/id :company/name {:company-router (prim/get-query CompanyRouter)}]
  (ui-company-router (prim/computed company-router {:X :a})))
Is there something wrong with this setup? @tony.kay

tony.kay19:02:44

looks ok to me

pvillegas1219:02:11

perhaps cursive is not loading the dependency properly

tony.kay19:02:25

cursive has nothing to do with it

tony.kay19:02:28

did you restart shadow-cljs

tony.kay19:02:35

after updating deps

pvillegas1219:02:17

what is the equivalent of nuking all deps for shadow cljs?

tony.kay19:02:18

it worked for me in workspaces

tony.kay19:02:25

no, there is never any need to do that

tony.kay19:02:32

shadow is excellent at figuring thta out

tony.kay19:02:41

I never clear it

tony.kay19:02:13

but in answer to your question: Remove .shadow-cljs (project root) and the cljs-runtime directories (build paths)

pvillegas1220:02:25

Should that be (prim/computed ~'current-route (prim/get-computed ~'this))?

pvillegas1220:02:52

Your ws has User being hit in the top router, not going through the nesting I have

tony.kay20:02:30

that line is about the “alternate” rendering when the route isn’t routed

tony.kay20:02:21

The point is I pass computed to a router, and it proxies it through to whatever target it is routed to…nesting does not matter….wait: you’re not trying to have it automatically go through all levels are you?

pvillegas1220:02:39

hahaha, that’s what I think 😛

tony.kay20:02:40

that is not what the code does

pvillegas1220:02:10

I’m passing the computed on the CompanyRouter which targets a component

pvillegas1220:02:18

so it is direct (like your User example)

pvillegas1220:02:01

There is one difference

tony.kay20:02:02

If you need to go through to the next level, then it has to be passed as computed again to the next router

pvillegas1220:02:16

My CompanyDetails target is deferring

tony.kay20:02:28

ah interesting…

pvillegas1220:02:30

the ProductDashboard is doing a dr/route-immediate that is basically the difference

tony.kay20:02:03

you probably need to force a refresh of the UI higher in the tree on route resolution

tony.kay20:02:30

so the computed is passed through again

pvillegas1220:02:42

how can I do that?

tony.kay20:02:11

no wait…Fulcro currently renders from root, so that should not be the problem

tony.kay20:02:39

since your use of computed should end up being called again

pvillegas1220:02:54

basically, teh example has https://github.com/fulcrologic/fulcro-incubator/blob/develop/src/workspaces/fulcro/incubator/routing_ws.cljs#L125 I am doing that on a defsc-route-target component with a dr/route-deferred

tony.kay20:02:27

I don’t have the time to play with it anymore today, sorry…the deffered is suspicious though

👍 5
pvillegas1220:02:58

What’s the way to load the incubator locally to tweak it’s behavior?

tony.kay20:02:42

you’re using deps.edn on your proj?

tony.kay20:02:07

just set to :local/root "path-to-incubator-clone". See tools deps docs

pvillegas1220:02:37

yeah, that’s it thanks!