Skip to content

Commit

Permalink
Dynamic routing improvements:
Browse files Browse the repository at this point in the history
* Dynamic routing now support cljs module loading, and dynamically adding targets to a router at runtime.
* registry-key->class now allow you to pass the class itself
  • Loading branch information
awkay committed Sep 18, 2023
1 parent 604251f commit 125884b
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 106 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.fulcrologic</groupId>
<artifactId>fulcro</artifactId>
<packaging>jar</packaging>
<version>3.6.11-SNAPSHOT</version>
<version>3.7.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
1 change: 1 addition & 0 deletions src/main/com/fulcrologic/fulcro/components.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[com.fulcrologic.fulcro.algorithms.do-not-use :as util]
[com.fulcrologic.fulcro.algorithms.denormalize :as fdn]
[com.fulcrologic.fulcro.algorithms.lookup :as ah]
[com.fulcrologic.fulcro.mutations :as m]
[com.fulcrologic.fulcro.raw.components :as rc]
[com.fulcrologic.guardrails.core :refer [>def]]
[clojure.set :as set])
Expand Down
35 changes: 13 additions & 22 deletions src/main/com/fulcrologic/fulcro/raw/components.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

(defonce ^:private component-registry (atom {}))

(defn legal-registry-lookup-key?
"Returns true if `k` is a legal thing to with `registry-key->class`. The registry contains keywords, but that helper
function accepts (and converts) strings or symbols as well."
[k]
(or (qualified-keyword? k) (qualified-symbol? k) (and (string? k) (str/includes? k "/"))))

;; Used internally by get-query for resolving dynamic queries (was created to prevent the need for external API change in 3.x)
(def ^:dynamic *query-state* nil)

Expand Down Expand Up @@ -124,9 +130,12 @@
"Look up the given component in Fulcro's global component registry. Will only be able to find components that have
been (transitively) required by your application.
`classname` can be a fully-qualified keyword or symbol."
`classname` can be a fully-qualified keyword, string, symbol, or component class. In the latter
case this function just acts as `identity`. This allows this function to act as a coercion
that ensures you have a class."
[classname]
(cond
(component-class? classname) classname
(keyword? classname) (get @component-registry classname)
(symbol? classname) (let [k (keyword (namespace classname) (name classname))]
(get @component-registry k))
Expand Down Expand Up @@ -703,9 +712,9 @@
"props" {"fulcro$queryid" :anonymous}})
{:query-id :anonymous})
(not ident) (assoc :ident
(fn [this props]
(when-let [k (union-keys props)]
[k (get props k)])))
(fn [this props]
(when-let [k (union-keys props)]
[k (get props k)])))
componentName (assoc :componentName componentName)))]
(assoc original-node :component component))
(let [real-id-key (ast-id-key children)
Expand Down Expand Up @@ -956,21 +965,3 @@
o# (cond-> o#
ident# (assoc :ident ident#))]
(def ~sym (nc ~query o#))))))

(comment
(def Person (entity->component
{:person/id 1
:ui/checked? true
:person/name "Bob"
:person/addresses [{:ui/autocomplete ""
:address/id 11
:address/street "111 Main St"}
{:ui/autocomplete ""
:address/id 12
:address/street "222 Main St"}]}
{:componentName ::MyThing}))

(def Address (get-subquery-component Person [:person/addresses]))

(get-ident Address {:address/id 99})
)
Loading

0 comments on commit 125884b

Please sign in to comment.