Fork me on GitHub
#fulcro
<
2018-11-18
>
sooheon12:11:22

For the routing example given in the book, and in fulcro template, what is the reason for the route ident being [(:page props) :top]? This seems to pollute the global props namespace with the naked names of each route, no?

currentoor19:11:02

@sooheon yes, but that’s exactly what idents do in a normalized DB, they put your data exactly two hops from the root of the database

currentoor19:11:19

don’t think of it as polluting a top level namespace, it much more like everything in a SQL database is two pieces of information away, table name and primary key, just like idents

currentoor19:11:21

also, in the book that is a very simple pedagogical example, you’re free to name your idents as you see fit

currentoor19:11:28

for example in my app i often use the namespace of the component’s file in the ident

currentoor19:11:09

I have a namespace called ucv.ui.wash-packages where i define

(defsc WashPackageAdmin [this props]
  {:query         (fn []
                    [:kind
                     {::table (prim/get-query Table)}])
   :ident         (fn [] [::admin :tab])
   :initial-state (fn [_] {:kind   ::admin
                           ::table (prim/get-initial-state Table {})})}
  (div :.ui.container
    ...))

currentoor19:11:29

Then for app state, and anywhere outside of this namespace this gives me an ident [:ucv.ui.wash-packages/admin :tab]

currentoor19:11:58

similar for a number of other routed components and sub-routers

currentoor19:11:31

so my routing tree definition looks like this

(def routing-tree
  (r/routing-tree
    (r/make-route :ucv.ui.wash-packages/admin
      [(r/router-instruction :root/top-router [:ucv.ui.wash-packages/admin :tab])
       (r/router-instruction :ucv.ui.wash-packages/admin-router [:ucv.ui.wash-packages/no-modal :tab])])

    (r/make-route :ucv.ui.wash-packages/details
      [(r/router-instruction :root/top-router [:ucv.ui.wash-packages/admin :tab])
       (r/router-instruction :ucv.ui.wash-packages/admin-router [:ucv.ui.wash-packages/details :tab])])

    (r/make-route :ucv.ui.wash-packages/new
      [(r/router-instruction :root/top-router [:ucv.ui.wash-packages/admin :tab])
       (r/router-instruction :ucv.ui.wash-packages/admin-router [:ucv.ui.wash-packages/new :tab])])

    ...))