Q: I’m starting with Malli in my re-frame client/forms. just checking to see if there’s any gotchas/advice from the team here?
It depends how you use Malli .. validation and coercion?
just validation for now. keeping it simple to start. schemas hardcoded in client code. later I intend to send schemas over the wire from the server
I’m using it as a validator for https://github.com/luciodale/fork in this iteration. thus no coercion since the form inputs will constrain the values
only notice is the bundle size, few hours away from making sci optional. Before that, the bundle is 200+kb. After, it's 1-12kb gzipped.
oh, and you should create validators ahead of time, running m/validate
can be orders of magnitude slower than just calling the returned function from m/validator
.
same applies to m/explain
vs m/explainer
and to m/decode
& m/decoder
(and encoders, generators etc)
fork-malli-example would be great gist/blog. Tried the first version of it, but was stumbling with nested data and for that case, did my own formik-kinda-thing for that project.
looking forward to seeing how the integration would look today @steveb8n !
thanks! great to know about the bundle increase.
and I’ll def the schemas for now since they are static
I’ll try and squeeze in a sample repo this week 🙂
Hey, is it possible to generate only alpha-numeric values with the :string
type? Currently it will go wild and generate whatever it wants (which makes sense)
Or is my only option to use a regular expression?
@kevin.van.rooijen you can use :gen/gen
to override the generator, there is one for alphanumeric. Or use :gen/elements
and list all valid in there.
I think :string
could have format option too, like in JSON Schema. But doesn't have that yet. One format could be :alphanumeric
, validator and generator would follow that...
Ah cool, the :gen/gen
is what I need. And it would be nice to allow something like a :format
option. Maybe make it extendable in some sort of way, perhaps a multimethod?
e.g.
[:string {:format :alphanumeric}]
(defmethod malli/format :alphanumeric [_ v]
,,,)
Something like this, or possibly more inline with how the registry for types works