Skip to content

Commit 3c02f9c

Browse files
authored
Merge pull request #1178 from frenchy64/select-keys-recompute
schematize children once in -applying (instead of 3x)
2 parents 180b717 + 15d0bd0 commit 3c02f9c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/malli/util.cljc

+6-3
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,12 @@
386386

387387
(defn -applying [f]
388388
(fn [_ children options]
389-
[(clojure.core/update children 0 #(m/schema % options))
390-
(clojure.core/update children 0 #(m/form % options))
391-
(delay (apply f (conj children options)))]))
389+
(let [children (clojure.core/update children 0 m/schema options)]
390+
[children
391+
(clojure.core/update children 0 m/-form)
392+
(delay (if (= 2 (count children))
393+
(f (nth children 0) (nth children 1) options)
394+
(apply f (conj children options))))])))
392395

393396
(defn -util-schema [m] (m/-proxy-schema m))
394397

test/malli/util_test.cljc

+11
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,14 @@
11331133
#?(:clj Exception, :cljs js/Error)
11341134
#":malli\.core/child-error"
11351135
(m/schema :union {:registry (merge (mu/schemas) (m/default-schemas))}))))
1136+
1137+
(deftest -applying-test
1138+
(let [times-initialized (atom 0)
1139+
map-proxy (m/-proxy-schema
1140+
{:type ::map-proxy
1141+
:max 0
1142+
:fn (fn [_ _ _]
1143+
(swap! times-initialized inc)
1144+
[[] [] (m/schema :map)])})]
1145+
(m/deref-all (m/schema [:select-keys map-proxy []] {:registry (merge (mu/schemas) (m/default-schemas))}))
1146+
(is (= 1 @times-initialized))))

0 commit comments

Comments
 (0)