New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: remove model.validate #96
Comments
I am using validate, but if the functionality can be offered via an optional argument to test(), then it seems fine. I do want to be able to test/validate an OM without throwing errors. ( related to #97 ) |
the upgrade plan could be:
optional: if ppl really want to validate a model instance with autocast explicitely disabled, we could add a second |
Can you explain a bit more what autocast does (and when - and on what lines of your code base it is most relevant)? |
Autocasting (also referred as duck typing in the docs) happens when checking the model definition for an instance. This is the To explain it with an example: const Person = ObjectModel({
name: String,
age: [Number]
});
const Lovers = ObjectModel({
husband: Person,
wife: Person
});
const joe = { name: "Joe", age: 42 };
const ann = new Person({
name: joe.name + "'s wife",
age: joe.age - 5
});
const couple = Lovers({
husband: joe, // object autocasted (duck typed)
wife: ann // object model
});
couple.husband instanceof Person === true // object has been autocasted to Person The This is really useful when you start to add methods or computed properties on your models. Usually, developers have to manually cast the data they receive to their suitable classes. With ObjectModel, you can use the type-checking phase to do this for you. Autocasts works for object models properties, but also for Array/Map/Set models items when inserted, and for FunctionModel arguments and return value. That's why I say ObjectModel is actually much more than just type checking. Once you have a mechanism to deeply traverse an object, and a declared definition to match with the developer's intention, you can bring all kind of interesting features to the table. |
Any ETA on this? Would love to have |
Since it's a breaking API change, it must be shipped in the next major version (v4). V4 roadmap is not yet determined, there is much more stuff I would like to put in. Don't expect it any time soon. Note that this is just API cleanup, not a new feature. You can already do |
Shipped in v4 👍 |
Argument: there is no common usecase where someone would want to validate a model instance with autocast explicitely disabled. So
model.test
could be enough if we add a custom error collector as second argument.Open to discussion, please comment if you need an { autocast: false } option. Use reactions to vote
The text was updated successfully, but these errors were encountered: