Skip to content

Commit

Permalink
[#38] Refactor zen.schema/compile-schema loop
Browse files Browse the repository at this point in the history
Co-authored-by: @islambegkatibov <79331750+islambegk@users.noreply.github.com>
  • Loading branch information
KGOH and katibov committed Jan 20, 2023
1 parent 865d98d commit d5d4ec3
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/zen/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@

compiled-schema-fn
(fn compiled-schema-fn [vtx data opts]
(loop [rs rulesets
vtx* (navigate-props (assoc vtx :type (:type schema)) data props opts)]
(if (empty? rs)
vtx*
(let [{when-fn :when rule-fn :rule} (first rs)]
(if (or (nil? when-fn) (when-fn data))
(recur (rest rs) (rule-fn vtx* data opts))
(recur (rest rs) vtx*))))))]
(let [vtx* (assoc vtx :type (:type schema))
vtx* (navigate-props vtx* data props opts)]
(loop [rs rulesets, vtx* vtx*]
(if (empty? rs)
vtx*
(let [{when-fn :when rule-fn :rule} (first rs)]
(if (or (nil? when-fn) (when-fn data))
(recur (rest rs) (rule-fn vtx* data opts))
(recur (rest rs) vtx*)))))))]

(wrap-with-post-hooks
compiled-schema-fn
Expand Down

0 comments on commit d5d4ec3

Please sign in to comment.