Skip to content

Commit

Permalink
Add check for componentName and display warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ourmaninamsterdam committed Feb 19, 2015
1 parent bff9464 commit fe44382
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion assets/js/components/DoughBaseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ define([], function() {
throw new Error('Element not supplied to DoughBaseComponent constructor');
}
this.config = $.extend({}, defaultConfig || {}, config || {});
this.componentName = this.config.componentName;

this.setElement($el);

this._setComponentName(this.config.componentName);
/*
Populate this array with the data attributes this module will use.
Exclude 'data-dough-' prefix, as this is automatically added.
Expand Down Expand Up @@ -152,6 +154,30 @@ define([], function() {
initialised && initialised.reject(this.componentName);
};

/**
* Checks whether a componentName has been passed via the config and whether it is actually
* present in [data-dough-component] and displays a warning
* @param {string} componentName The componentName to check
* @private
*/
DoughBaseComponentProto._setComponentName = function(componentName) {
var warning;

if (typeof componentName !== 'undefined') {
if (this.$el.data('dough-component').indexOf(componentName)) {
warning = '\'' + componentName + '\' componentName was not found in the data-dough-component attribute';
}
this.componentName = componentName;
}
else {
warning = 'componentName not specified';
}

if (warning && console && console.warn) {
console.warn(warning);
}
};

return DoughBaseComponent;

});

0 comments on commit fe44382

Please sign in to comment.