refactor components to be in a registry.

This commit is contained in:
Keegan
2016-02-01 14:56:47 -08:00
parent 7e3dbfa148
commit bca1975d8e
22 changed files with 126 additions and 94 deletions
+18 -2
View File
@@ -18,6 +18,7 @@ var _ = require('../vendor/minified/minified')._;
var ClayItem = require('./clay-item');
var utils = require('../lib/utils');
var ClayEvents = require('./clay-events');
var componentStore = require('./component-registry');
/**
* @extends ClayEvents
@@ -89,8 +90,20 @@ function ClayConfig(settings, config, $rootContainer) {
return _settings;
};
// attach event methods
ClayEvents.call(self, $rootContainer);
/**
* Register a component to Clay. This must be called prior to .build();
* @param {{}} component - the clay component to register
* @param {string} component.name - the name of the component
* @param {string} component.template - HTML template to use for the component
* @param {{}} component.manipulator - methods to attach to the component
* @param {function} component.manipulator.set - set manipulator method
* @param {function} component.manipulator.get - get manipulator method
* @param {{}} component.defaults - template defaults
* @param {function} [component.initialize] - method to scaffold the component
*/
self.registerComponent = function(component) {
componentStore[component.name] = component;
};
self.build = function() {
self.trigger(self.EVENTS.BEFORE_BUILD);
@@ -99,6 +112,9 @@ function ClayConfig(settings, config, $rootContainer) {
self.trigger(self.EVENTS.AFTER_BUILD);
};
// attach event methods
ClayEvents.call(self, $rootContainer);
/**
* Add item(s) to the config
* @param {Clay~ConfigItem|array} items