Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #195 from MozillaReality/checkattributes
Browse files Browse the repository at this point in the history
Check component attributes not defined on schema
  • Loading branch information
fernandojsg authored Jul 29, 2020
2 parents 94a6da4 + 883cfb3 commit 3697ae3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class Component {
}
}
}

if (process.env.NODE_ENV !== "production" && props !== undefined) {
this.checkUndefinedAttributes(props);
}
}

this._pool = null;
Expand All @@ -32,6 +36,11 @@ export class Component {
}
}

// @DEBUG
if (process.env.NODE_ENV !== "production") {
this.checkUndefinedAttributes(source);
}

return this;
}

Expand Down Expand Up @@ -63,6 +72,19 @@ export class Component {
getName() {
return this.constructor.getName();
}

checkUndefinedAttributes(src) {
const schema = this.constructor.schema;

// Check that the attributes defined in source are also defined in the schema
Object.keys(src).forEach(srcKey => {
if (!schema.hasOwnProperty(srcKey)) {
console.warn(
`Trying to set attribute '${srcKey}' not defined in the '${this.constructor.name}' schema. Please fix the schema, the attribute value won't be set`
);
}
});
}
}

Component.schema = {};
Expand Down

0 comments on commit 3697ae3

Please sign in to comment.