Skip to content

Commit a0bcc56

Browse files
committed
share child in ref
1 parent 469e4be commit a0bcc56

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/malli/core.cljc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,10 +2086,13 @@
20862086
(-check-children! :ref properties children 1 1)
20872087
(when-not (-reference? ref)
20882088
(-fail! ::invalid-ref {:ref ref}))
2089-
(let [rf (or (and lazy (-memoize (fn [] (schema (mr/-schema (-registry options) ref) options))))
2090-
(when-let [s (mr/-schema (-registry options) ref)] (-memoize (fn [] (schema s options))))
2091-
(when-not allow-invalid-refs
2092-
(-fail! ::invalid-ref {:type :ref, :ref ref})))
2089+
(let [child (delay (or (mr/-schema (-registry options) ref)
2090+
(when-not allow-invalid-refs
2091+
(-fail! ::invalid-ref {:type :ref, :ref ref}))))
2092+
rf (if lazy
2093+
(-memoize (fn [] (schema @child options)))
2094+
(let [s @child]
2095+
(-memoize (fn [] (schema s options)))))
20932096
children (vec children)
20942097
form (delay (-simple-form parent properties children identity options))
20952098
cache (-create-cache options)
@@ -2110,18 +2113,17 @@
21102113
(fn [x]
21112114
(if-let [f @vol]
21122115
(f x)
2113-
(let [s (schema (mr/-schema reg ref) options)
2116+
(let [s @child
21142117
f (binding [*ref-validators* (assoc ref-validators id vol)]
21152118
(-validator s))]
21162119
(vreset! vol f)
21172120
(f x)))))
21182121
(if-some [vol (ref-validators id)]
21192122
#(@vol %)
21202123
(let [vol (volatile! nil)
2121-
s (or (when-let [s (mr/-schema (-registry options) ref)]
2122-
(schema s options))
2123-
(when-not allow-invalid-refs
2124-
(-fail! ::invalid-ref {:type :ref, :ref ref})))
2124+
s (if-let [s @child]
2125+
(schema s options)
2126+
(-fail! ::invalid-ref {:type :ref, :ref ref}))
21252127
f (binding [*ref-validators* (assoc ref-validators id vol)]
21262128
(-validator s))]
21272129
(vreset! vol f)

0 commit comments

Comments
 (0)