mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
begin attempt at Component/template joint def
This commit is contained in:
@@ -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)
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user