Fork me on GitHub
#malli
<
2020-07-23
>
ikitommi08:07:43

sci will be an optional dependency, why? • faster standalone usage for JVM (2.5sec -> 0.5sec to load `malli.core`) • smaller js-bundles: 120kb -> 7kb first cut: https://github.com/metosin/malli/pull/227

ikitommi08:07:17

to make the sci-integration explicit, might be a good idea to make the whole default options customizable, instead of just the default registry. would allow one to pass sci as the default :evaluator , one could pass in default custom localizations for error messages etc. Wrote an issue here: https://github.com/metosin/malli/issues/228

ikitommi08:07:02

comments welcome. it’s a rainy day, should have few hours later today to do that.

plexus08:07:00

should a schema-schema's properties delegate to the referenced schema?

plexus08:07:20

(schema/properties (malli.core/-deref (schema/schema :ars/address)))
  (schema/properties (schema/schema :ars/address))

plexus08:07:56

the first returns a properties map, the second returns nil. would be nice if it actually returned the properties of the child schema

plexus08:07:01

(I'm upgrading our project to the latest Malli. Nice addition of RefSchema and schema-schema!)

plexus09:07:34

I guess the question is how transparent a RefSchema is expected to be. We had our implementation of a RefSchema before Malli added it, and in our case we tried to make it largely transparent, e.g. it implements MapSchema and LensSchema which delegate to the child schema. Was very convenient but maybe you prefer to be explicit and have (if (satisfies? RefSchema s) (-deref s) s) checks

ikitommi09:07:50

Good question. :schema can now have it's own properties: [::m/schema {:title "foo"} :ars/address]

ikitommi09:07:47

would help if there was distinction between properties and derived/accumulated properties

ikitommi09:07:55

properties are used in transforming schemas, e.g. into map-format. If they are looked from child, the map-format would duplicate the properties into ::m/schema

ikitommi09:07:30

a new Protocol / method would solve that, but not sure if that's the right fix

plexus09:07:26

makes sense to keep them separate if they have different uses, maybe some more helpers would already go a long way, there's no deref yet for instance, only -deref. A version of deref/resolve that checks for RefSchema and otherwise returns the schema directly would also be nice.

plexus09:07:33

what about if you do an update-in, but one of the schemas on the path is not a map schema but a reference to a map schema? should that work? (we do stuff like that and it's quite handy :))

ikitommi13:07:05

Merged the SCI Optional PR. From Changelog:

* 23.7.2020
  * **BREAKING:**: `sci` is not a default dependency. Enabling sci-support:
    * **Clojure**: add a dependency to `borkdude/sci`
    * **ClojureScript**: also require `sci.core` (directly or via `:preloads`)

👍 3
ikitommi13:07:43

before and after (a small sample app)

borkdude13:07:15

What is the total size of the app before and after, un-gzipped? What does optimized mean, Clojure advanced?

ikitommi13:07:28

here’s the javascript:

➜  malli git:(master) ✗ ls -lh app2-sci
total 1536
-rw-r--r--  1 tommi  staff   8.8K Jul 23 16:43 app.js
-rw-r--r--  1 tommi  staff   177K Jul 23 16:43 cljs.js
-rw-r--r--  1 tommi  staff    16K Jul 23 16:43 malli.js
-rw-r--r--  1 tommi  staff   2.0K Jul 23 16:43 manifest.edn
-rw-r--r--  1 tommi  staff   556K Jul 23 16:43 sci.js

➜  malli git:(master) ✗ ls -lh app2
total 288
-rw-r--r--  1 tommi  staff    10K Jul 23 16:41 app.js
-rw-r--r--  1 tommi  staff   102K Jul 23 16:41 cljs.js
-rw-r--r--  1 tommi  staff    24K Jul 23 16:41 malli.js
-rw-r--r--  1 tommi  staff   987B Jul 23 16:41 manifest.edn

ikitommi13:07:07

manually zipped:

➜  malli git:(master) ✗ ls -lh app2-sci
total 344
-rw-r--r--  1 tommi  staff   2.3K Jul 23 16:43 app.js.gz
-rw-r--r--  1 tommi  staff    35K Jul 23 16:43 cljs.js.gz
-rw-r--r--  1 tommi  staff   4.7K Jul 23 16:43 malli.js.gz
-rw-r--r--  1 tommi  staff   624B Jul 23 16:43 manifest.edn.gz
-rw-r--r--  1 tommi  staff   119K Jul 23 16:43 sci.js.gz

➜  malli git:(master) ✗ ls -lh app2
total 80
-rw-r--r--  1 tommi  staff   3.0K Jul 23 16:41 app.js.gz
-rw-r--r--  1 tommi  staff    22K Jul 23 16:41 cljs.js.gz
-rw-r--r--  1 tommi  staff   6.5K Jul 23 16:41 malli.js.gz
-rw-r--r--  1 tommi  staff   370B Jul 23 16:41 manifest.edn.gz

ikitommi13:07:54

the app itself is silly, bare-bones malli with few schemas: https://github.com/metosin/malli/blob/master/app/malli/app2.cljc

borkdude13:07:05

modules are a bit confusing since one thing can get randomly moved from one module to another

borkdude13:07:32

but overall, this is a win for people who don't want to use sci

ikitommi13:07:22

so total sizes: • js: 757,8kb -> 136kb • gz: 161kb -> 31,5kb , so 1/5 the size.

ikitommi13:07:34

yup (javascript) is 223kB unpacked, so we can say malli can be small too. or batteries-included.

ikitommi14:07:42

anyone btw interested in writing a malli->typescript transformer? in a project with both, might be useful, most likely fun

ikitommi14:07:48

with yup, you can say:

type Person = yup.InferType<typeof personSchema>;

ikitommi14:07:43

I don’t think it would be much more work than the malli -> JSON Schema.

ikitommi14:07:56

might be wrong 🙂