pass Clay to component initializer

This commit is contained in:
Keegan
2016-02-15 11:39:25 -08:00
parent 64fa83528e
commit ea5c349047
3 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ function ClayConfig(settings, config, $rootContainer) {
var _item = _.copyObj(item); var _item = _.copyObj(item);
_item.clayId = _items.length; _item.clayId = _items.length;
var clayItem = new ClayItem(_item).initialize(); var clayItem = new ClayItem(_item).initialize(self);
if (_item.id) { if (_item.id) {
_itemsById[_item.id] = clayItem; _itemsById[_item.id] = clayItem;
+3 -2
View File
@@ -48,11 +48,12 @@ function ClayItem(config) {
/** /**
* Run the initializer if it exists and attaches the css to the head. * Run the initializer if it exists and attaches the css to the head.
* Passes minified as the first param * Passes minified as the first param
* @param {ClayConfig} clay
* @returns {ClayItem} * @returns {ClayItem}
*/ */
self.initialize = function() { self.initialize = function(clay) {
if (typeof _component.initialize === 'function') { if (typeof _component.initialize === 'function') {
_component.initialize.call(self, minified); _component.initialize.call(self, minified, clay);
} }
return self; return self;
}; };
+3 -3
View File
@@ -96,9 +96,9 @@ describe('ClayItem', function() {
describe('.initialize()', function() { describe('.initialize()', function() {
it('calls component initializer with the ClayItem as context', function() { it('calls component initializer with the ClayItem as context', function() {
var initializeSpy = sinon.spy(componentRegistry.select, 'initialize'); var initializeSpy = sinon.spy(componentRegistry.select, 'initialize');
var clayItem = fixture.clayItem('select').initialize(); var clayConfig = fixture.clayConfig(['select']);
assert(initializeSpy.alwaysCalledOn(clayItem)); assert(initializeSpy.alwaysCalledOn(clayConfig.getItemsByType('select')[0]));
assert(initializeSpy.alwaysCalledWith(minified)); assert(initializeSpy.alwaysCalledWith(minified, clayConfig));
initializeSpy.restore(); initializeSpy.restore();
}); });