Fork me on GitHub
#malli
<
2020-07-06
>
steveb8n08:07:56

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?

Vincent Cantin08:07:23

It depends how you use Malli .. validation and coercion?

steveb8n09:07:28

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

steveb8n09:07:42

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

ikitommi09:07:02

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.

ikitommi09:07:41

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.

ikitommi09:07:37

same applies to m/explain vs m/explainer and to m/decode & m/decoder (and encoders, generators etc)

ikitommi09:07:33

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.

ikitommi09:07:27

looking forward to seeing how the integration would look today @steveb8n !

steveb8n09:07:31

thanks! great to know about the bundle increase.

steveb8n09:07:51

and I’ll def the schemas for now since they are static

steveb8n09:07:17

I’ll try and squeeze in a sample repo this week 🙂

Kevin10:07:47

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)

Kevin10:07:16

Or is my only option to use a regular expression?

ikitommi10:07:09

@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.

ikitommi10:07:24

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...

Kevin10:07:07

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?

Kevin10:07:10

e.g. [:string {:format :alphanumeric}]

(defmethod malli/format :alphanumeric [_ v]
  ,,,)
Something like this, or possibly more inline with how the registry for types works