Throw errors when components don't look like components (#980)
- instead of mysteriously throwing an error later on.
This commit is contained in:
parent
b1475cb309
commit
98c4252840
1 changed files with 16 additions and 10 deletions
|
@ -23,22 +23,28 @@ class Skinner {
|
||||||
if (this.components === null) {
|
if (this.components === null) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Attempted to get a component before a skin has been loaded."+
|
"Attempted to get a component before a skin has been loaded."+
|
||||||
"This is probably because either:"+
|
" This is probably because either:"+
|
||||||
" a) Your app has not called sdk.loadSkin(), or"+
|
" a) Your app has not called sdk.loadSkin(), or"+
|
||||||
" b) A component has called getComponent at the root level"
|
" b) A component has called getComponent at the root level",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var comp = this.components[name];
|
let comp = this.components[name];
|
||||||
if (comp) {
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
// XXX: Temporarily also try 'views.' as we're currently
|
// XXX: Temporarily also try 'views.' as we're currently
|
||||||
// leaving the 'views.' off views.
|
// leaving the 'views.' off views.
|
||||||
var comp = this.components['views.'+name];
|
if (!comp) {
|
||||||
if (comp) {
|
comp = this.components['views.'+name];
|
||||||
return comp;
|
|
||||||
}
|
}
|
||||||
throw new Error("No such component: "+name);
|
|
||||||
|
if (!comp) {
|
||||||
|
throw new Error("No such component: "+name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// components have to be functions.
|
||||||
|
const validType = typeof comp === 'function';
|
||||||
|
if (!validType) {
|
||||||
|
throw new Error(`Not a valid component: ${name}.`);
|
||||||
|
}
|
||||||
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
load(skinObject) {
|
load(skinObject) {
|
||||||
|
|
Loading…
Reference in a new issue