Suppress warnings for KnotEntity creation

This commit is contained in:
barsdeveloper
2022-12-17 09:56:25 +01:00
parent 479db1e987
commit 6bf1174c38
6 changed files with 69 additions and 53 deletions

View File

@@ -14,7 +14,7 @@ export default class IEntity extends Observable {
static attributes = {}
constructor(values = {}) {
constructor(values = {}, suppressWarns = false) {
super()
/**
* @param {Object} target
@@ -36,19 +36,21 @@ export default class IEntity extends Observable {
defaultValue = new defaultType()
}
if (!(attribute in attributes)) {
console.warn(
`Attribute ${prefix}${attribute} in the serialized data is not defined in ${this.constructor.name}.attributes`
)
} else if (
valuesPropertyNames.length > 0
&& !(attribute in values)
&& defaultValue !== undefined
&& !(defaultValue instanceof TypeInitialization && (!defaultValue.showDefault || defaultValue.ignored))
) {
console.warn(
`${this.constructor.name} will add attribute ${prefix}${attribute} not defined in the serialized data`
)
if (!suppressWarns) {
if (!(attribute in attributes)) {
console.warn(
`Attribute ${prefix}${attribute} in the serialized data is not defined in ${this.constructor.name}.attributes`
)
} else if (
valuesPropertyNames.length > 0
&& !(attribute in values)
&& defaultValue !== undefined
&& !(defaultValue instanceof TypeInitialization && (!defaultValue.showDefault || defaultValue.ignored))
) {
console.warn(
`${this.constructor.name} will add attribute ${prefix}${attribute} not defined in the serialized data`
)
}
}
// Not instanceof because all objects are instenceof Object, exact match needed