Liking cljdoc? Tell your friends :D

fulcro.client.routing


-get-missing-routesclj/s

(-get-missing-routes reconciler
                     state-map
                     {:keys [handler route-params] :as params})

Returns a sequence of routes that need to be loaded in order for routing to succeed.

Returns a sequence of routes that need to be loaded in order for routing to succeed.
raw docstring

-is-dynamic-router?clj/s

(-is-dynamic-router? component)

Returns true if the given component (instance) is a DynamicRouter.

Returns true if the given component (instance) is a DynamicRouter.
raw docstring

-load-dynamic-routeclj/s

(-load-dynamic-route state-atom pending-route-handler route-to-load finish-fn)
(-load-dynamic-route state-atom
                     pending-route-handler
                     route-to-load
                     finish
                     attempt
                     delay)

Triggers the actual load of a route, and retries if the networking is down. If the pending route (in state) has changed between retries, then no further retries will be attempted. Exponential backoff with a 10 second max is used as long as retries are being done.

Triggers the actual load of a route, and retries if the networking is down. If the pending route (in state) has changed
between retries, then no further retries will be attempted. Exponential backoff with a 10 second max is used as long
as retries are being done.
raw docstring

-load-routesclj/s

(-load-routes {:keys [state] :as env} routes)

-process-pending-route!clj/s

(-process-pending-route! {:keys [state reconciler] :as env})

Finish doing the routing after a module completes loading

Finish doing the routing after a module completes loading
raw docstring

-route-target-missing?clj/s

(-route-target-missing? ident)

Returns true iff the given ident has no component loaded into the dynamic routing multimethod.

Returns true iff the given ident has no component loaded into the dynamic routing multimethod.
raw docstring

-update-routing-queriesclj/s

(-update-routing-queries state reconciler {:keys [handler route-params]})

PRIVATE.

Given the reconciler, state, and a routing tree route: finds and sets all of the dynamic queries needed to accomplish that route. Returns the updated state. reconciler can be nil, in which case UI refresh may not happen, but that is useful for SSR.

PRIVATE.

Given the reconciler, state, and a routing tree route: finds and sets all of the dynamic queries needed to
accomplish that route. Returns the updated state. reconciler can be nil, in which case UI refresh may not
happen, but that is useful for SSR.
raw docstring

add-route-stateclj/s

(add-route-state state-map target-kw component)

bad-routeclj/s

(bad-route page)

coerce-paramclj/smultimethod


compile-errorclj

(compile-error env form message ex)

current-routeclj/s

(current-route state-map-or-router-table router-id)

Get the current route (an ident) from the router with the given id. You can pass the entire app database, the routers table, or the props of a component that has queried for the router table as the first argument to this function. Thus, it can be used easily from within a mutation or in a component to find (and display) the current route:

(defmutation do-something-with-routes [params]
  (action [{:keys [state]}]
    (let [current (r/current-route state :top-router)]
    ...)))

(defsc NavBar [this props]
  {:query (fn [] [[r/routers-table '_]])
   :initial-state (fn [params] {})}
  (let [current (r/current-route props :top-router)]
    ...))
Get the current route (an ident) from the router with the given id. You can pass the entire app database, the routers table,
or the props of a component that has queried for the router table as the first argument to this function.
Thus, it can be used easily from within a mutation or in a component to find (and display) the current route:

```
(defmutation do-something-with-routes [params]
  (action [{:keys [state]}]
    (let [current (r/current-route state :top-router)]
    ...)))

(defsc NavBar [this props]
  {:query (fn [] [[r/routers-table '_]])
   :initial-state (fn [params] {})}
  (let [current (r/current-route props :top-router)]
    ...))
```
raw docstring

defrouterclj/smacro

(defrouter & args)

DEPRECATED: Use defsc-router instead.

Generates a component with a union query that can route among the given screens.

(defrouter ComponentName keyword-for-router-id
  ident-generator
  kw Component
  kw2 Component2
  ...)

The first screen listed will be the 'default' screen that the router will be initialized to show.

The ident-generator can be:

. A lamba receiving this and props that must return a legal ident from the props of any of the listed components . A vector listing the table prop and id prop that will be in the state of the screen

Examples:

(fn [this props] [(:screen props) (:id props)]) ; General-purpose [:screen :id] ; shorthand for prior example (fn [t p] [(:screen p :constant-id]) ; must use fn form if id is some kind of constant (ident [t p] [(:screen p) :x]) ; name of the lambda is ignored (fn is recommended) ...

NOTES:

  • All Component screens must have initial state
  • All Component screens must have a query
  • All Component screens must have state that the ident-fn can use to generate a proper ident from your ident generator.
DEPRECATED: Use `defsc-router` instead.

   Generates a component with a union query that can route among the given screens.

```
(defrouter ComponentName keyword-for-router-id
  ident-generator
  kw Component
  kw2 Component2
  ...)
```

The first screen listed will be the 'default' screen that the router will be initialized to show.

The `ident-generator` can be:

. A lamba receiving `this` and `props` that must return a legal ident from the props of any of the listed components
. A vector listing the table prop and id prop that will be in the state of the screen

Examples:

(fn [this props] [(:screen props) (:id props)])  ; General-purpose
[:screen :id]                                    ; shorthand for prior example
(fn [t p] [(:screen p :constant-id])             ; must use fn form if id is some kind of constant
(ident [t p] [(:screen p) :x])                   ; name of the lambda is ignored (fn is recommended)
...

NOTES:
- All Component screens *must* have initial state
- All Component screens *must* have a query
- All Component screens *must* have state that the ident-fn can use to generate a proper ident from your ident generator.
raw docstring

defsc-routerclj/smacro

(defsc-router sym arglist options & body)

Define a router component.

This is just like defsc, BUT generates a pair of components that optimize query performance and allow for efficient UI changes. The options are identical to defsc, except:

Required Options:

  • :router-id - An ID for the router
  • :ident - An ident that works across all of the routing targets. This kind of router generates a union query, so this ident function must work on ALL router targets, and MUST vary the FIRST elements of the ident to identiy which screen to show.
  • :default-route - The Class of the router target that is the default (initial) route.
  • :router-targets - A map of ident tables to router targets. This map MUST correspond to the TABLE name that the router target lives in, and the Class of the router target component.

You may NOT define a :query or :initial-state for a router.

All other defsc options are supported.

(defsc-router TopRouter [this props]
  {
   ;; REQUIRED for router:
   :router-id :top-router
   :ident (fn [] [(:table props) (:id props)]
   :router-targets  {:A A :B B :C C}
   :default-route A

   :css [] ; garden css rules
   :css-include [] ; list of components that have CSS to compose towards root.

   ; React Lifecycle Methods (this in scope)
   :initLocalState            (fn [] ...) ; CAN BE used to call things as you might in a constructor. Return value is initial state.
   :shouldComponentUpdate     (fn [next-props next-state] ...)

   :componentDidUpdate        (fn [prev-props prev-state snapshot] ...) ; snapshot is optional, and is 16+. Is context for 15
   :componentDidMount         (fn [] ...)
   :componentWillUnmount      (fn [] ...)

   ;; DEPRECATED IN REACT 16 (to be removed in 17):
   :componentWillReceiveProps        (fn [next-props] ...)
   :componentWillUpdate              (fn [next-props next-state] ...)
   :componentWillMount               (fn [] ...)

   ;; Replacements for deprecated methods in React 16.3+
   :UNSAFE_componentWillReceiveProps (fn [next-props] ...)
   :UNSAFE_componentWillUpdate       (fn [next-props next-state] ...)
   :UNSAFE_componentWillMount        (fn [] ...)

   ;; ADDED for React 16:
   :componentDidCatch         (fn [error info] ...)
   :getSnapshotBeforeUpdate   (fn [prevProps prevState] ...)
   :getDerivedStateFromProps  (fn [props state] ...)
Define a router component.

This is just like `defsc`, BUT generates a pair of components that optimize query performance and allow for efficient
UI changes.  The options are identical to `defsc`, except:

Required Options:

- `:router-id` - An ID for the router
- `:ident` - An ident that works across all of the routing targets. This kind of router generates a union query,
             so this ident function must work on ALL router targets, and MUST vary the FIRST elements of the ident
             to identiy which screen to show.
- `:default-route` - The Class of the router target that is the default (initial) route.
- `:router-targets` - A map of ident tables to router targets.  This map MUST correspond to the TABLE name that
the router target lives in, and the Class of the router target component.

You may NOT define a `:query` or `:initial-state` for a router.

All other `defsc` options are supported.

 ```
 (defsc-router TopRouter [this props]
   {
    ;; REQUIRED for router:
    :router-id :top-router
    :ident (fn [] [(:table props) (:id props)]
    :router-targets  {:A A :B B :C C}
    :default-route A

    :css [] ; garden css rules
    :css-include [] ; list of components that have CSS to compose towards root.

    ; React Lifecycle Methods (this in scope)
    :initLocalState            (fn [] ...) ; CAN BE used to call things as you might in a constructor. Return value is initial state.
    :shouldComponentUpdate     (fn [next-props next-state] ...)

    :componentDidUpdate        (fn [prev-props prev-state snapshot] ...) ; snapshot is optional, and is 16+. Is context for 15
    :componentDidMount         (fn [] ...)
    :componentWillUnmount      (fn [] ...)

    ;; DEPRECATED IN REACT 16 (to be removed in 17):
    :componentWillReceiveProps        (fn [next-props] ...)
    :componentWillUpdate              (fn [next-props next-state] ...)
    :componentWillMount               (fn [] ...)

    ;; Replacements for deprecated methods in React 16.3+
    :UNSAFE_componentWillReceiveProps (fn [next-props] ...)
    :UNSAFE_componentWillUpdate       (fn [next-props next-state] ...)
    :UNSAFE_componentWillMount        (fn [] ...)

    ;; ADDED for React 16:
    :componentDidCatch         (fn [error info] ...)
    :getSnapshotBeforeUpdate   (fn [prevProps prevState] ...)
    :getDerivedStateFromProps  (fn [props state] ...)
 ```
 
raw docstring

defsc-router*clj

(defsc-router* env router-sym arglist options body)

defsc-router-router-element*clj

(defsc-router-router-element* env router-sym union-sym arglist options)

dynamic-route-keyclj/s


DynamicRouterclj/s≠

clj
cljs
(DynamicRouter)

get-dynamic-router-queryclj/s

(get-dynamic-router-query router-id)

Get the query for the router with the given router-id.

Get the query for the router with the given router-id.
raw docstring

get-dynamic-router-targetclj/smultimethod

Get the component that renders the given screen type. The parameter is simply the keyword of the module/component. Note that all have to match: the module name in the compiler that contains the code for the component, the first element of the ident returned by the component, and the keyword passed to this multimethod to retrieve the component.

Get the component that renders the given screen type. The parameter is simply the keyword of the module/component.
Note that all have to match: the module name in the compiler that contains the code for the component,
the first element of the ident returned by the component, and the keyword passed to this multimethod to retrieve
the component.
raw docstring

install-route*clj/s

(install-route* state-map target-kw component)

Implementation of mutation. Useful for SSR setup.

Implementation of mutation. Useful for SSR setup.
raw docstring

make-routeclj/s

(make-route name routing-instructions)

Make a route name that executes the provided routing instructions to change which screen in on the UI. routing-instructions must be a vector. Returns an item that can be passed to routing-tree to generate your overall application's routing plan.

(make-route :route/a [(router-instruction ...) ...])

Make a route name that executes the provided routing instructions to change which screen in on the UI. routing-instructions
must be a vector. Returns an item that can be passed to `routing-tree` to generate your overall application's routing
plan.

`(make-route :route/a [(router-instruction ...) ...])`

raw docstring

route-to*clj/s

(route-to* state-map bidi-match)

Implementation of routing tree data manipulations on app state. Returns an updated app state.

WARNING: This function will not trigger dynamic module loading, as it is only responsible for returning a state-map that has been set (as far as is possible) to the given route. You typically do not want to use this on a client, but exists a separate function for server-side rendering to be easily able to route, since no dynamic code loading will be needed.

Implementation of routing tree data manipulations on app state. Returns an updated app state.

WARNING: This function will not trigger dynamic module loading, as it is
only responsible for returning a state-map that has been set (as far as is possible) to the given route. You typically
do *not* want to use this on a client, but exists a separate function for server-side rendering to be easily able
to route, since no dynamic code loading will be needed.
raw docstring

route-to-impl!clj/s

(route-to-impl! {:keys [state reconciler] :as env} bidi-match)

Mutation implementation, for use as a composition into other mutations. This function can be used from within mutations. If a DynamicRouter is used in your routes, then this function may trigger code loading. Once the loading is complete (if any is needed), it will trigger the actual UI routing.

If routes are being loaded, then the root property in your app state :fulcro.client.routing/pending-route will be your bidi-match. You can use a link query to pull this into your UI to show some kind of indicator.

NOTE: this function updates application state and must not be used from within a swap on that state.

Mutation implementation, for use as a composition into other mutations. This function can be used
from within mutations. If a DynamicRouter is used in your routes, then this function may trigger
code loading. Once the loading is complete (if any is needed), it will trigger the actual UI routing.

If routes are being loaded, then the root property in your app state :fulcro.client.routing/pending-route
will be your `bidi-match`. You can use a link query to pull this into your UI to show some kind of indicator.

NOTE: this function updates application state and *must not* be used from within a swap on that state.
raw docstring

router-instructionclj/s

(router-instruction router-id target-screen-ident)

Return the definition of a change-route instruction.

Return the definition of a change-route instruction.
raw docstring

routers-tableclj/s


routing-treeclj/s

(routing-tree & routes)

Generate initial state for your application's routing tree. The return value of this should be merged into your overall app state in your Root UI component

(defui Root
  static prim/InitialAppState
  (initial-state [cls params]  (merge {:child-key (prim/get-initial-state Child)}
                                      (routing-tree
                                        (make-route :route/a [(router-instruction ...)])
                                        ...)))
  ...
Generate initial state for your application's routing tree. The return value of this should be merged into your overall
app state in your Root UI component

```
(defui Root
  static prim/InitialAppState
  (initial-state [cls params]  (merge {:child-key (prim/get-initial-state Child)}
                                      (routing-tree
                                        (make-route :route/a [(router-instruction ...)])
                                        ...)))
  ...
```
raw docstring

routing-tree-keyclj/s


set-ident-route-paramsclj/s

(set-ident-route-params ident route-params)

Replace any keywords of the form :params/X with the value of (get route-params :X) in the given ident. By default the value of the parameter (which comes in as a string) will be converted to an int if it is all digits, and will be converted to a keyword if it is all letters. If you want to customize the coercion, just:

(defmethod r/coerce-param :param/NAME [k v] (transform-it v))
Replace any keywords of the form :params/X with the value of (get route-params :X) in the given ident. By default the value
of the parameter (which comes in as a string) will be converted to an int if it is all digits, and will be
converted to a keyword if it is all letters. If you want to customize the coercion, just:

```
(defmethod r/coerce-param :param/NAME [k v] (transform-it v))
```
raw docstring

set-routeclj/s


set-route*clj/s

(set-route* state-map router-id screen-ident)

Set the given screen-ident as the current route on the router with the given ID. Returns a new application state map.

Set the given screen-ident as the current route on the router with the given ID. Returns a new application
state map.
raw docstring

ui-dynamic-routerclj/s

(ui-dynamic-router props)

(update-routing-links state-map {:keys [handler route-params]})

Given the app state map, returns a new map that has the routing graph links updated for the given route/params as a bidi match.

This function should only be used if you only use static UI routing.

If you use DynamicRouter then you must use route-to-impl! instead.

Given the app state map, returns a new map that has the routing graph links updated for the given route/params
as a bidi match.

***This function should only be used if you only use static UI routing.***

If you use DynamicRouter then you must use `route-to-impl!` instead.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close