Fork me on GitHub
#fulcro
<
2019-02-18
>
pvillegas1213:02:57

I’m trying to use dynamic routing, but on initial load I can’t see the ident I’m giving to a defsc-route-target in the normalized database

pvillegas1213:02:22

I have

(defrouter RootRouter
  [this props]
  {:router-targets [CompanyDashboard CompanyDetails]})

pvillegas1213:02:38

and

(defsc-route-target CompanyDashboard [this {:keys [all-companies] :as props}]
  {:ident (fn [] [:COMPONENT/by-id :company-dashboard])
   :query [{:all-companies (prim/get-query CompanyQuery)}]
   :route-segment   (fn [] ["dashboard-empresa"])
   :route-cancelled (fn [_])
   :will-enter      (fn [reconciler _]
                      (dr/route-deferred ["dashboard-empresa"]
                        #(df/load reconciler :all-companies CompanyQuery
                           {:post-mutation `dr/target-ready
                            :post-mutation-params {:target [:COMPONENT/by-id :company-dashboard]}})))
   :will-leave      (fn [_] (js/console.log "Leaving company dashboard") true)}
  (dom/div
    (count all-companies)))

pvillegas1213:02:39

the route-deferred part is issuing the load correctly, but CompanyDashboard is not updating the all-companies data structure (ie. (= (count all-companies) 0) always in the UI

pvillegas1213:02:43

all-companies is getting populated at the root level, maybe that’s why?

pvillegas1214:02:37

assoc’ing the data in [:COMPONENT/by-id :company-dashboard [ [ ... ] ]] but same behavior

hmaurer15:02:02

Is anyone aware of a vanilla JS library that takes the om.next/fulcro approach of normalising using the UI tree?

tony.kay16:02:49

@pvillegas12 you have to call a change-route on start to start the state machines

tony.kay16:02:21

and route-deferred takes an IDENT, not a route

tony.kay16:02:50

(route-deferred [:COMPONENT/by-id :company-dashboard] ...)

tony.kay16:02:23

The change-route goes in the client startup

tony.kay16:02:40

:started-callback/`:client-did-mount`

pvillegas1218:02:28

@U0CKQ19AQ still getting the same result. The routing appears to work but I’m not getting the state I should be getting.

pvillegas1218:02:34

I’m also getting a warning 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: :RootRouter

pvillegas1218:02:23

Forgot the initial state for the router, now it’s updating, still have the above warning though

tony.kay18:02:42

that warning is almost certainly because you didn’t start out with a change-route

tony.kay18:02:18

it’s not initial-state, it’s change-route that initializes the router’s state machine

pvillegas1220:02:16

I have

(defn ^:export init []
  (reset! SPA (fc/new-fulcro-client
                :started-callback
                (fn [{:keys [reconciler] :as app}]
                  (dr/change-route reconciler ["dashboard-empresa"]))
 

tony.kay20:02:11

strange…and you still see a warning from the router?

tony.kay21:02:29

I probably just need to make it so that there is some call that scans for all routers and starts their state machines

tony.kay21:02:55

my guess is there’s a nested router that is getting somehow used before being activated

mss16:02:05

encountering a weird bug where a ref isn’t in the env of my mutation. my call to transact! looks about like what you’d expect (run inside of the component):

(fp/transact! this `[(forms/reset-sign-in-form {})])
my component is a top level fulcro-router route, if that might make any difference

tony.kay05:02:57

ref is only set in two cases: 1. It is called from a component that has an ident 2. You explicitly pass an ident to transact! (arity 3) If that component has an ident, then that is strange.