Fork me on GitHub
#malli
<
2023-02-20
>
Joel01:02:23

Does walk not give the custom map data? Do I need to use m/ast for that? I thought “options” would represent the :label info i embedded.

(m/walk [:map
         [:ts {:label :domain/ts} [:and {:label :domain/specific} :int [:> 0]]]]
        (fn [s p c o] (println o) s))

ikitommi06:02:51

Morning. what do you mean with “custom map data”? the last argument is top-level options. if you want to read the schema properties, you should use (m/properties s). For map-entries, there are 2 options: 1. if the schemas has entries, e.g. m/entries returns non-nil, walk those too 2. use option {::m/walk-entry-vals true}

(m/walk 
 [:map
  [:ts {:label :domain/ts} [:and {:label :domain/specific} :int [:> 0]]]]
 (fn [s p c o] (some-> s m/properties println) s)
 {::m/walk-entry-vals true})
;{:label :domain/specific}
;{:label :domain/ts}
;=> [:map [:ts {:label :domain/ts} [:and {:label :domain/specific} :int [:> 0]]]] 

💯 2
hifumi12313:02:42

I’ve just checked bundle size for my cljs app I’ve noticed malli.core is the 2nd largest thing after clojurescript itself. Are there any tips to reducing the impact of malli on bundle size?

ikitommi13:02:25

really good question! Malli is build for DCE, but multimethods can’t be DCEd. There are examples in malli repo (and a guide in README) for a minimal bundle, with just selected schemas and schema applications (validation). With the minimal set, Malli starts with 1.6KB zipped

ikitommi13:02:51

to disable default registry, you can:

:closure-defines {malli.registry/type "custom"}
… but then you have to pull the selected schemas at runtime:
(require '[malli.registry :as mr])

(mr/set-default-registry!
  {:string (m/-string-schema)
   :maybe (m/-maybe-schema)
   :map (m/-map-schema)})

ikitommi13:02:01

if you depend on an optional ns, like malli.generator - multimethod is mounted for ALL schemas, regardless if that’s needed or not. Not sure if there is a way to make the extensions slimmer.

ikitommi13:02:25

but, code size is a priority issue. all help & issues welcome.

ikitommi13:02:14

If all schemas had a concrete class impl, e.g. MapSchema, AndSchema etc, the DCE might work also for the extension cases. Not sure. If it did, would be open to changing this in the core.

hifumi12315:02:46

Super helpful information! This allowed me to reduce malli's footprint from 139.75 kb to 75.09 kb 🙂

hifumi12315:02:00

Thank you!

👍 2
jmmk18:02:46

I’m using malli to parse/validate a string format that has different types of separators e.g. a/b/c/d e f g where part 1 has elements separated by / and each part is separated by " " I see instaparse has the ability to ignore certain characters > In instaparse, you can use angle brackets <> to hide parsed elements, suppressing them from the tree output. Does malli have any such capability to ignore certain elements in the parsed output?

jmmk18:02:26

It’s not hard to “just ignore those keys” when pulling data out, but it’s a bit annoying to have to invent tags for useless data

jmmk18:02:05

e.g.

[:catn
  [:element1 some-schema]
  [:sep1 slash]
  [:element2 some-schema]
  [:sep2 slash]]

Ben Sless18:02:12

Call them :_

jmmk18:02:35

malli doesn’t allow repeated tags

jmmk18:02:45

Duplicate key :_

Ben Sless19:02:13

damn, but at least you don't have to think about names then, :_0, etc