sylvainpolletvillard / ObjectModel

Strong Dynamically Typed Object Modeling for JavaScript
http://objectmodel.js.org
MIT License
467 stars 30 forks source link

How can i return a « cleaned » object ? #167

Closed gordielachance closed 1 year ago

gordielachance commented 1 year ago

Hi ! I’ve built a model with your (nice!) library. Works fine! Is there a way to use it to return a « cleaned » version of the data used to fill the model? I mean, removing all the properties that have returned an error.

Is that possible?

thanks!

sylvainpolletvillard commented 1 year ago

Validation can occur in two different scenarios: instanciation and mutation. On instanciation, if the object does not validate its model, it will be fully rejected. On mutation, if this mutation does not validate its model, the mutation will not be applied at all.

You should be able to apply your custom "clean-up" logic with a custom error collector: https://objectmodel.js.org/#doc-custom-collectors

sylvainpolletvillard commented 1 year ago

closed after inactivity