Implemented templated views in script tags

This commit is contained in:
Borys Levytskyi
2015-04-03 20:25:40 +03:00
parent 665bedbc85
commit 9a40c1e3bd
5 changed files with 51 additions and 24 deletions

View File

@@ -0,0 +1,21 @@
(function(app, is){
app.modelView = function (modelCtor, builder) {
var name = getKey(modelCtor);
app.di.register(name, builder);
};
app.buildViewFor = function(model) {
var key = getKey(model.constructor);
var builder = this.di.resolve(key);
return builder.renderView(model);
};
function getKey(modelCtor) {
return getFunctionName(modelCtor) + "ViewBuilder";
}
function getFunctionName(func) {
var str = func.toString();
return str.substr(8, str.indexOf('(') - 8).trim();
}
})(window.app, window.is);