(add-route-state state-map target-kw component)
(bad-route page)
(compile-error env form message ex)
(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)] ...)) ```
(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:
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.
(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
, :ident
, 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`, `:ident`, 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] ...) ```
(defsc-router* env router-sym arglist options body)
(defsc-router-router-element* env router-sym union-sym arglist options)
(DynamicRouter)
(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.
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.
(install-route* state-map target-kw component)
Implementation of mutation. Useful for SSR setup.
Implementation of mutation. Useful for SSR setup.
(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 ...) ...])`
(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.
(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.
(router-instruction router-id target-screen-ident)
Return the definition of a change-route instruction.
Return the definition of a change-route instruction.
(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 ...)]) ...))) ... ```
(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)) ```
(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.
(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.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close