first cut of UI.bind

This commit is contained in:
David Greenspan
2013-11-05 13:39:01 -08:00
parent 4086612e31
commit c0186ebd8f

View File

@@ -226,6 +226,36 @@ UI.emboxValue = function (funcOrValue, equals) {
}
};
UI.bind = function (kindOrFunc, options) {
var boxedOptions = {};
for (var k in options)
boxedOptions[k] = UI.emboxValue(options[k]);
if (typeof kindOrFunc === 'function') {
return function () {
var kind = kindOrFunc();
if (! kind)
return null;
if ((! UI.isComponent(kind)) || kind.isInited)
throw new Error("Expected Component kind");
return kind.extend(boxedOptions);
};
} else {
var kind = kindOrFunc;
if (! kind)
return null;
if ((! UI.isComponent(kind)) || kind.isInited)
throw new Error("Expected Component kind");
return kind.extend(boxedOptions);
}
};
////////////////////////////////////////
var sanitizeComment = function (content) {