Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 98c4252

Browse files
authored
Throw errors when components don't look like components (#980)
- instead of mysteriously throwing an error later on.
1 parent b1475cb commit 98c4252

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/Skinner.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ class Skinner {
2323
if (this.components === null) {
2424
throw new Error(
2525
"Attempted to get a component before a skin has been loaded."+
26-
"This is probably because either:"+
26+
" This is probably because either:"+
2727
" a) Your app has not called sdk.loadSkin(), or"+
28-
" b) A component has called getComponent at the root level"
28+
" b) A component has called getComponent at the root level",
2929
);
3030
}
31-
var comp = this.components[name];
32-
if (comp) {
33-
return comp;
34-
}
31+
let comp = this.components[name];
3532
// XXX: Temporarily also try 'views.' as we're currently
3633
// leaving the 'views.' off views.
37-
var comp = this.components['views.'+name];
38-
if (comp) {
39-
return comp;
34+
if (!comp) {
35+
comp = this.components['views.'+name];
36+
}
37+
38+
if (!comp) {
39+
throw new Error("No such component: "+name);
40+
}
41+
42+
// components have to be functions.
43+
const validType = typeof comp === 'function';
44+
if (!validType) {
45+
throw new Error(`Not a valid component: ${name}.`);
4046
}
41-
throw new Error("No such component: "+name);
47+
return comp;
4248
}
4349

4450
load(skinObject) {

0 commit comments

Comments
 (0)