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
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
comments welcome. it’s a rainy day, should have few hours later today to do that.
should a schema-schema's properties delegate to the referenced schema?
(schema/properties (malli.core/-deref (schema/schema :ars/address)))
(schema/properties (schema/schema :ars/address))
the first returns a properties map, the second returns nil. would be nice if it actually returned the properties of the child schema
(I'm upgrading our project to the latest Malli. Nice addition of RefSchema and schema-schema!)
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
Good question. :schema
can now have it's own properties:
[::m/schema {:title "foo"} :ars/address]
would help if there was distinction between properties and derived/accumulated properties
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
a new Protocol / method would solve that, but not sure if that's the right fix
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.
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 :))
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`)
before and after (a small sample app)
What is the total size of the app before and after, un-gzipped? What does optimized mean, Clojure advanced?
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
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
the app itself is silly, bare-bones malli with few schemas: https://github.com/metosin/malli/blob/master/app/malli/app2.cljc
ok
shadow config: https://github.com/metosin/malli/blob/master/shadow-cljs.edn
modules are a bit confusing since one thing can get randomly moved from one module to another
but overall, this is a win for people who don't want to use sci
so total sizes: • js: 757,8kb -> 136kb • gz: 161kb -> 31,5kb , so 1/5 the size.
yup (javascript) is 223kB unpacked, so we can say malli can be small too. or batteries-included.
anyone btw interested in writing a malli->typescript transformer? in a project with both, might be useful, most likely fun
with yup, you can say:
type Person = yup.InferType<typeof personSchema>;
I don’t think it would be much more work than the malli -> JSON Schema.
might be wrong 🙂