Permalink
Browse files

using the new Y.mojito.ViewRenderer factory to access the renderer in…

…stance. removing unnecesary dependencies and unnecessary configuration that is not semantically correct for action-context or mojito-client
  • Loading branch information...
caridy committed Oct 30, 2012
1 parent da53ea3 commit 6b2a5c4360cc2101dcaccc2b069c4e1afc9917c3
@@ -338,7 +338,6 @@ callback({
}, '0.1.0', {requires: [
'mojito',
'mojito-util',
- 'mojito-perf',
'mojito-assets-addon',
'mojito-params-addon'
]});
@@ -54,7 +54,8 @@ YUI.add('mojito-partial-addon', function(Y, NAME) {
mojitView = instance.views[view];
data = data || {}; // default null data to empty view template
- renderer = new Y.mojito.ViewRenderer(mojitView.engine);
+ renderer = Y.mojito.ViewRenderer(mojitView.engine,
+ this.ac.staticAppConfig.viewEngine);
Y.log('Rendering "' + view + '" view for "' + (instance.id || '@' +
instance.type) + '"', 'debug', NAME);
@@ -282,7 +282,6 @@ YUI.add('mojito-action-context', function(Y, NAME) {
actionFunction,
perf = Y.mojito.perf.timeline('mojito', 'ac:init', 'set up AC object', command),
error,
- staticAppConfig = store.getAppConfig(store.getStaticContext()),
my;
my = this;
@@ -304,12 +303,8 @@ YUI.add('mojito-action-context', function(Y, NAME) {
this.instance = command.instance;
this._adapter = opts.adapter;
- // in here we should whitelist the stuff we need
- this.staticAppConfig = {
- pathToRoot: staticAppConfig.pathToRoot,
- cacheViewTemplates: staticAppConfig.cacheViewTemplates,
- viewEngineOptions: staticAppConfig.viewEngine
- };
+ // pathToRoot, viewEngine, amoung others will be available through this.
+ this.staticAppConfig = store.getAppConfig(store.getStaticContext());
// Create a function which will properly delegate to the dispatcher to
// perform the actual processing.
@@ -373,12 +368,6 @@ YUI.add('mojito-action-context', function(Y, NAME) {
mojitView,
renderer = null,
contentType,
- contentPath,
-
- // static app configuration options
- pathToRoot = this.staticAppConfig.pathToRoot,
- cacheViewTemplates = this.staticAppConfig.cacheViewTemplates,
- viewEngineOptions = this.staticAppConfig.viewEngine || {},
perf = Y.mojito.perf.timeline('mojito', 'ac.done',
'time to execute ac.done process', this.command);
@@ -405,9 +394,6 @@ YUI.add('mojito-action-context', function(Y, NAME) {
meta.http.headers = meta.http.headers || {};
meta.view = meta.view || {};
- // Cache all templates by default
- meta.view.cacheTemplates = (cacheViewTemplates === false ? false : true);
-
// Check to see we need to serialize the data
if (meta.serialize && serializer[meta.serialize]) {
// Warning: this metod can change the "meta" object
@@ -515,30 +501,10 @@ YUI.add('mojito-action-context', function(Y, NAME) {
// Y.log('Rendering "' + meta.view.name + '" view for "' +
// (instance.id || '@' + instance.type) + '"', 'info', NAME);
- contentPath = mojitView['content-path'];
- // this is mainly used by html5app
- if (pathToRoot) {
- contentPath = pathToRoot + contentPath;
- }
-
- // optimize for server only
- if ('server' === context.runtime) {
- renderer = CACHE.renderers[mojitView.engine];
- if (!renderer) {
- // viewEngineOptions are app level
- CACHE.renderers[mojitView.engine] = renderer =
- new (Y.mojito.addons.viewEngines[mojitView.engine])('', viewEngineOptions);
- }
- renderer.viewId = meta.view.id;
- renderer.render(data, instance.type, contentPath, adapter, meta, more);
- } else {
- renderer = new Y.mojito.ViewRenderer(
- mojitView.engine,
- meta.view.id,
- viewEngineOptions
- );
- renderer.render(data, instance.type, contentPath, adapter, meta, more);
- }
+ // we use the view renderer factory
+ // because it provides caching capabilities for better performance
+ renderer = Y.mojito.ViewRenderer(mojitView.engine, this.staticAppConfig.viewEngine);
+ renderer.render(data, instance, mojitView, adapter, meta, more);
} else {
@@ -57,7 +57,7 @@ YUI.add('mojito-client', function(Y, NAME) {
// this is the heart of mojitProxy.render(), but it needs to be a separate
// function called once we have mojit type details
- function privateRender(mp, data, view, cb) {
+ function privateRender(mp, data, view, viewEngine, cb) {
var mojitView,
renderer;
@@ -71,7 +71,8 @@ YUI.add('mojito-client', function(Y, NAME) {
data.mojit_assets = data.mojit_assets || mp._assetsRoot;
mojitView = mp._views[view];
- renderer = new Y.mojito.ViewRenderer(mojitView.engine);
+ renderer = Y.mojito.ViewRenderer(mojitView.engine, viewEngine);
+
Y.log('Rendering "' + view + '" in Binder', 'debug', NAME);
renderer.render(data, mp.type, mojitView['content-path'], {
buffer: '',
@@ -674,6 +675,7 @@ YUI.add('mojito-client', function(Y, NAME) {
doRender: function(mp, data, view, cb) {
+ var viewEngine = this.appConfig.viewEngine;
if (!mp._views || !mp._assetsRoot) {
this.resourceStore.expandInstanceForEnv('client', {type: mp.type}, mp.context,
function(err, typeInfo) {
@@ -686,10 +688,10 @@ YUI.add('mojito-client', function(Y, NAME) {
}
mp._views = typeInfo.views;
mp._assetsRoot = typeInfo.assetsRoot;
- privateRender(mp, data, view, cb);
+ privateRender(mp, data, view, viewEngine, cb);
});
} else {
- privateRender(mp, data, view, cb);
+ privateRender(mp, data, view, viewEngine, cb);
}
},

0 comments on commit 6b2a5c4

Please sign in to comment.