Replies: 5 comments 3 replies
-
I lean towards mutable registry by default, maybe with a caveat that individual schemas can't be registered, only entire "modules", thus forcing users to load their model and not just mutate things "irresponsibly" |
Beta Was this translation helpful? Give feedback.
-
I think the core issue is that the default registry is "privileged" over user provided ones. Because passing fewer arguments uses the default and no one wants to pass more arguments there is a pressure to have the default registry be all things to all people. One alternative I'd like to add to the mix is some convenience for users to re-export all the functions that would be the entry point of a custom registry with their own registry "partial"-ed in. It would be the users responsibility to merge whatever library schemas they want into their registry, and they would access malli's functionality via com.company.malli. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the comments. I think this is the expression problem: one the other hand, we have a big number of schema applications (creation, validation, explaining, parsing, transforming, json-schema, generation, inferring, plantuml, ...) and then we have a set of Schemas that have implementations for those applications. @bowbahdoe The convenience funtion(s) to would have to cover all applications. e.g. I'm today in favour of option 2 (but far from being happy with it), because: Good
Bad
|
Beta Was this translation helpful? Give feedback.
-
maybe: #583. |
Beta Was this translation helpful? Give feedback.
-
Going with initial 2, via #583. Keeping this open as there is still options on how to move forward (closing everything, starting from empty registry etc.) |
Beta Was this translation helpful? Give feedback.
-
Background
Currently, Malli defaults to immutable registry. Immutability makes it simple, no surprises (of the registry changing over time, causing hard to debug problems) and there is only stuff user has explicitly defined in it.
But, in real life, this is not easy: using custom schemas mean you need to construct a new immutable registry with the schemas in and pass it in to every method in malli api. This is a lot of boilerplate and is prone to errors.
One can also override the default registry and this is what most of the projects I've done have used. But - it requires extra JVM property & Compiler option in CLJS. It's too invasive.
Problem Statement
There should be easy way to start using extra schemas as modules, e.g. all
malli.time
schemasAlternatives
1) don't do anything, Immutable is Simple, who wan't Easy anyway?
Immutable is GOOD, and one can use schema instances already instead of schema types (and registry lookup):
2) allow swapping the default registry without JVM/Compiler options
e.g. swappable by default, there could be a
"strict"
mode not allowing this (for the paranoid).This would also allows managed mutability:
3) mutable registry by default, like spec, whoever can register whatever they want:
Elsewhere
Related issues:
Related PRs:
Beta Was this translation helpful? Give feedback.
All reactions