mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-27 20:36:33 -04:00
pass Clay to component initializer
This commit is contained in:
@@ -56,7 +56,7 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
var _item = _.copyObj(item);
|
||||
_item.clayId = _items.length;
|
||||
|
||||
var clayItem = new ClayItem(_item).initialize();
|
||||
var clayItem = new ClayItem(_item).initialize(self);
|
||||
|
||||
if (_item.id) {
|
||||
_itemsById[_item.id] = clayItem;
|
||||
|
||||
@@ -48,11 +48,12 @@ function ClayItem(config) {
|
||||
/**
|
||||
* Run the initializer if it exists and attaches the css to the head.
|
||||
* Passes minified as the first param
|
||||
* @param {ClayConfig} clay
|
||||
* @returns {ClayItem}
|
||||
*/
|
||||
self.initialize = function() {
|
||||
self.initialize = function(clay) {
|
||||
if (typeof _component.initialize === 'function') {
|
||||
_component.initialize.call(self, minified);
|
||||
_component.initialize.call(self, minified, clay);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
@@ -96,9 +96,9 @@ describe('ClayItem', function() {
|
||||
describe('.initialize()', function() {
|
||||
it('calls component initializer with the ClayItem as context', function() {
|
||||
var initializeSpy = sinon.spy(componentRegistry.select, 'initialize');
|
||||
var clayItem = fixture.clayItem('select').initialize();
|
||||
assert(initializeSpy.alwaysCalledOn(clayItem));
|
||||
assert(initializeSpy.alwaysCalledWith(minified));
|
||||
var clayConfig = fixture.clayConfig(['select']);
|
||||
assert(initializeSpy.alwaysCalledOn(clayConfig.getItemsByType('select')[0]));
|
||||
assert(initializeSpy.alwaysCalledWith(minified, clayConfig));
|
||||
initializeSpy.restore();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user