如何访问 Malli 地图架构中分配有键的属性?
给定一个像 [:map [:key {:optional true} :int]]
这样的 Malli 地图模式,我如何获取在中分配关键字 :key
的属性写步行者时的地图?在此示例中,这些是 {:optional true}
。
正如您在下面的示例中看到的,walker 访问地图的所有“值”,在本例中仅访问 :int
模式,然后访问 :map
架构。有没有办法到达中间步骤、“模式”和 :key
的属性?
(malli/walk
[:map [:key {:optional true} :int]]
(fn [schema path children options]
(println "Schema:" schema)
(println "Path:" path)
(println "Children:" children)
(println "Options:" options)
(println "Properties:" (malli/properties schema))
(println))) => nil
;; Schema: :int
;; Path: [:key]
;; Children: nil
;; Options: nil
;; Properties: nil
;;
;; Schema: [:map [:key {:optional true} :int]]
;; Path: []
;; Children: [[:key {:optional true} nil]]
;; Options: nil
;; Properties: nil
Given a Malli map schema like [:map [:key {:optional true} :int]]
, how do I get at the properties assigned the keyword :key
in the map when writing a walker? In this example, these are {:optional true}
.
As you can see in the below example the walker visits all the "values" of the map, in this case just the :int
schema, and then out to the :map
schema. Is there any way to get to the inbetween step, the "schema" and properties of :key
?
(malli/walk
[:map [:key {:optional true} :int]]
(fn [schema path children options]
(println "Schema:" schema)
(println "Path:" path)
(println "Children:" children)
(println "Options:" options)
(println "Properties:" (malli/properties schema))
(println))) => nil
;; Schema: :int
;; Path: [:key]
;; Children: nil
;; Options: nil
;; Properties: nil
;;
;; Schema: [:map [:key {:optional true} :int]]
;; Path: []
;; Children: [[:key {:optional true} nil]]
;; Options: nil
;; Properties: nil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将选项
:malli.core/walk-entry-vals
传递给 walker 函数。You need to pass the option
:malli.core/walk-entry-vals
to the walker function.