malli

https://github.com/metosin/malli :malli:
steveb8n 2020-07-06T08:15:56.054800Z

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?

2020-07-06T08:51:23.055100Z

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

steveb8n 2020-07-06T09:24:28.056300Z

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

steveb8n 2020-07-06T09:25:42.057200Z

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

ikitommi 2020-07-06T09:31:02.059900Z

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.

ikitommi 2020-07-06T09:32:41.062300Z

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.

ikitommi 2020-07-06T09:33:37.063900Z

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

ikitommi 2020-07-06T09:37:33.067500Z

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.

ikitommi 2020-07-06T09:38:27.068800Z

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

steveb8n 2020-07-06T09:39:31.069300Z

thanks! great to know about the bundle increase.

steveb8n 2020-07-06T09:39:51.069800Z

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

steveb8n 2020-07-06T09:44:17.070400Z

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

kwrooijen 2020-07-06T10:13:47.071400Z

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)

kwrooijen 2020-07-06T10:14:16.071900Z

Or is my only option to use a regular expression?

ikitommi 2020-07-06T10:20:09.074400Z

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

ikitommi 2020-07-06T10:21:24.076700Z

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

kwrooijen 2020-07-06T10:25:07.077800Z

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?

kwrooijen 2020-07-06T10:26:10.079Z

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

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