sylvainpolletvillard / ObjectModel

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

Request, soft sealed models #109

Closed Amenocy closed 5 years ago

Amenocy commented 5 years ago

hi soft sealed models don't accept new attributes but if constructor object contains other attributes soft sealed object don't throw the error, just doesn't use new attributes.

sylvainpolletvillard commented 5 years ago

Hello,

Could you explicit what you mean by "soft" model ? Also please provide a code example so I can understand better what you mean

Amenocy commented 5 years ago

currently sealed model throw error on set new attr, but soft sealed model doesn't throw an error and doesn't use new attr just ignore it. I want to use it in parse API data and ignore unwanted attributes.

sylvainpolletvillard commented 5 years ago

I don't know what a "soft" model is, this word is not used anywhere in ObjectModel documentation

Sealed model constructors actually throw erros when you pass an object with an undeclared property, as shown in the official docs:

const Package = ObjectModel({
    name: String,
    config: { verbose: [Boolean] }
}, { sealed: true });

const Foo = new Package({ name: "foo", _id: 1 });
// > TypeError: property _id is not declared in the sealed model definition
Amenocy commented 5 years ago

sorry, it is a future request.

sylvainpolletvillard commented 5 years ago

I'm sorry but I don't understand your issue, and you don't answer to my questions. Please provide more details, including a code example with the expected result. For now, I'm going to close this issue.