mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:02:46 +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');
|
||||
|
||||
// Helps debug widgets
|
||||
if (Ember.testing) {
|
||||
if (Discourse.Environment === "development" || Ember.testing) {
|
||||
const ds = this.defaultState(attrs);
|
||||
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) {
|
||||
Ember.warn(`you need a key when using state ${this.name}`);
|
||||
throw `you need a key when using state in ${this.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user