Skip to content

Commit

Permalink
begin attempt at Component/template joint def
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Jun 17, 2013
1 parent 3df9d66 commit 6ef5185
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/ui/component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
// @export UI
UI = {
isComponentClass: function (value) {
return (typeof value === 'function') &&
(value === Component ||
(value.protoype instanceof Component));
},
// Generated templates are put here. This object must
// be populated before any Components are actually
// created, i.e. as the compiled template scripts are
// evaluated.
_templates: {}
};

var constructorsLocked = true;

var templatesAssigned = false;
var global = (function () { return this; })();

// @export Component
Component = function (args) {
if (constructorsLocked)
Expand Down Expand Up @@ -30,6 +47,19 @@ Component = function (args) {
this._childUpdaters = {};
this.elements = {};

if (! templatesAssigned) {
_.each(UI._templates, function (v, k) {
if (UI.isComponentClass(global[k])) {
if (k.prototype.hasOwnProperty('render'))
throw new Error(
'Component "' + k + '" has both a render method ' +
'implementation and a template of that name');
k.prototype.render = v;
}
});
templatesAssigned = true;
}

this.constructed();
};

Expand Down

0 comments on commit 6ef5185

Please sign in to comment.