Raise an error if a widget doesn't have a key but uses state

This commit is contained in:
Robin Ward 2017-01-30 12:02:55 -05:00
parent 0c6ad455a3
commit d4bbdcd7d6
1 changed files with 3 additions and 3 deletions

View File

@ -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}`;
}
}