mirror of
https://github.com/discourse/discourse.git
synced 2025-05-15 13:57:25 +08:00
Raise an error if a widget doesn't have a key but uses state
This commit is contained in:
parent
0c6ad455a3
commit
d4bbdcd7d6
@ -145,12 +145,12 @@ export default class Widget {
|
|||||||
this.keyValueStore = register.lookup('key-value-store:main');
|
this.keyValueStore = register.lookup('key-value-store:main');
|
||||||
|
|
||||||
// Helps debug widgets
|
// Helps debug widgets
|
||||||
if (Ember.testing) {
|
if (Discourse.Environment === "development" || Ember.testing) {
|
||||||
const ds = this.defaultState(attrs);
|
const ds = this.defaultState(attrs);
|
||||||
if (typeof ds !== "object") {
|
if (typeof ds !== "object") {
|
||||||
Ember.warn(`defaultState must return an object`);
|
throw `defaultState must return an object`;
|
||||||
} else if (Object.keys(ds).length > 0 && !this.key) {
|
} else if (Object.keys(ds).length > 0 && !this.key) {
|
||||||
Ember.warn(`you need a key when using state ${this.name}`);
|
throw `you need a key when using state in ${this.name}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user