Skip to content

Commit

Permalink
Merge pull request #1125 from frenchy64/issue-1124-pointer-identity
Browse files Browse the repository at this point in the history
Close #1124: only assume string interning in cljs
  • Loading branch information
ikitommi authored Nov 23, 2024
2 parents 0680cdd + 4a6e081 commit f8c6a9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2724,8 +2724,10 @@
(merge (predicate-schemas) (class-schemas) (comparator-schemas) (type-schemas) (sequence-schemas) (base-schemas)))

(def default-registry
(let [strict (identical? mr/mode "strict")
custom (identical? mr/type "custom")
(let [strict #?(:cljs (identical? mr/mode "strict")
:default (= mr/mode "strict"))
custom #?(:cljs (identical? mr/type "custom")
:default (= mr/type "custom"))
registry (if custom (mr/fast-registry {}) (mr/composite-registry (mr/fast-registry (default-schemas)) (mr/var-registry)))]
(when-not strict (mr/set-default-registry! registry))
(mr/registry (if strict registry (mr/custom-default-registry)))))
Expand Down
7 changes: 4 additions & 3 deletions src/malli/registry.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#?(:clj (:import (java.util HashMap Map))))

#?(:cljs (goog-define mode "default")
:clj (def mode (as-> (or (System/getProperty "malli.registry/mode") "default") $ (.intern $))))
:clj (def mode (or (System/getProperty "malli.registry/mode") "default")))

#?(:cljs (goog-define type "default")
:clj (def type (as-> (or (System/getProperty "malli.registry/type") "default") $ (.intern $))))
:clj (def type (or (System/getProperty "malli.registry/type") "default")))

(defprotocol Registry
(-schema [this type] "returns the schema from a registry")
Expand Down Expand Up @@ -40,7 +40,8 @@
(def ^:private registry* (atom (simple-registry {})))

(defn set-default-registry! [?registry]
(if-not (identical? mode "strict")
(if-not #?(:cljs (identical? mode "strict")
:default (= mode "strict"))
(reset! registry* (registry ?registry))
(throw (ex-info "can't set default registry, invalid mode" {:mode mode, :type type}))))

Expand Down

0 comments on commit f8c6a9a

Please sign in to comment.