Compare commits

..

2 Commits

Author SHA1 Message Date
Andrey Antukh
33a174adf5 Add the ability to use scheme for obj/reify set operations 2026-01-21 14:22:40 +01:00
Andrey Antukh
545a558812 Add the ability to provide decode options 2026-01-21 14:22:00 +01:00

View File

@@ -172,6 +172,9 @@
schema-1 (c/get params :schema-1)
this? (c/get params :this false)
decode-options
(c/get params :decode-options)
fn-sym
(-> (gensym (str "internal-fn-" (str/slug pname) "-"))
(with-meta {:tag 'function}))
@@ -198,13 +201,28 @@
get-expr)])
(when set-expr
[(make-sym pname "set-fn")
(if this?
`(fn [v#]
(let [~this-sym (~'js* "this")
~fn-sym ~set-expr]
(.call ~fn-sym ~this-sym ~this-sym v#)))
set-expr)])
(concat
(when schema-n
[coercer-sym `(sm/coercer ~schema-n)])
[(make-sym pname "set-fn")
(if this?
`(fn [~'v]
(let [~this-sym (~'js* "this")
~fn-sym ~set-expr
~'v (json/->clj ~'v ~decode-options)
~'v ~(if schema-n
`(~coercer-sym ~'v)
'v)]
(.call ~fn-sym ~this-sym ~this-sym ~'v)))
`(fn [~'v]
(let [~this-sym (~'js* "this")
~fn-sym ~set-expr
~'v (json/->clj ~'v ~decode-options)
~'v ~(if schema-n
`(~coercer-sym ~'v)
'v)]
(.call ~fn-sym ~this-sym ~'v))))]))
(when fn-expr
(concat
@@ -223,14 +241,14 @@
~@(if schema-1
[fn-sym `(fn* [param#]
(let [param# (json/->clj param#)
(let [param# (json/->clj param# ~decode-options)
param# (~coercer-sym param#)]
(~fn-sym param#)))]
[])
~@(if schema-n
[fn-sym `(fn* []
(let [params# (into-array (cljs.core/js-arguments))
params# (mfu/bean params#)
params# (json/->clj params# ~decode-options)
params# (~coercer-sym params#)]
(apply ~fn-sym params#)))]
[])