Permalink
Browse files

Remove call to flush for client side hb to prevent multiple done calls

  • Loading branch information...
1 parent 8ec5131 commit c9cfcf164b7bdc6f2f4d8fe0b414ad83715b0af6 Michael Ridgway committed Aug 29, 2012
Showing with 36 additions and 32 deletions.
  1. +17 −14 lib/app/addons/view-engines/hb.client.js
  2. +19 −18 lib/app/addons/view-engines/hb.server.js
@@ -33,22 +33,24 @@ YUI.add('mojito-hb', function(Y, NAME) {
* @param {object} meta Optional metadata.
*/
render: function (data, mojitType, tmpl, adapter, meta) {
- var handler = function (err, obj) {
- if (err) {
- adapter.error(err);
- return;
- }
+ var cacheTemplates = meta && meta.view && meta.view.cacheTemplates,
+ handler = function (err, obj) {
+ if (err) {
+ adapter.error(err);
+ return;
+ }
- if (obj) {
- adapter.flush(obj.compiled(data), meta);
- Y.log('render complete for view "' +
- tmpl + '"',
- 'mojito', 'qeperf');
- }
- adapter.done('', meta);
- };
+ if (obj) {
+ adapter.done(obj.compiled(data), meta);
+ Y.log('render complete for view "' +
+ tmpl + '"',
+ 'mojito', 'qeperf');
+ } else {
+ adapter.done('', meta);
+ }
+ };
- this._getTemplateObj(tmpl, !meta.view.cacheTemplates, handler);
+ this._getTemplateObj(tmpl, !cacheTemplates, handler);
},
/**
@@ -63,6 +65,7 @@ YUI.add('mojito-hb', function(Y, NAME) {
_getTemplateObj: function (tmpl, bypassCache, callback) {
if (cache[tmpl] && !bypassCache) {
callback(null, cache[tmpl]);
+ return;
}
this._loadTemplate(tmpl, function (err, str) {
@@ -38,25 +38,26 @@ YUI.add('mojito-hb', function(Y, NAME) {
* @param {boolean} more
*/
render: function (data, mojitType, tmpl, adapter, meta, more) {
- var handler = function (err, obj) {
- if (err) {
- adapter.error(err);
- return;
- }
-
- if (obj) {
- adapter.flush(obj.compiled(data), meta);
- Y.log('render complete for view "' +
- tmpl + '"',
- 'mojito', 'qeperf');
- }
-
- if (!more || false === more) {
- adapter.done('', meta);
- }
- };
+ var cacheTemplates = meta && meta.view && meta.view.cacheTemplates,
+ handler = function (err, obj) {
+ if (err) {
+ adapter.error(err);
+ return;
+ }
+
+ if (obj) {
+ adapter.flush(obj.compiled(data), meta);
+ Y.log('render complete for view "' +
+ tmpl + '"',
+ 'mojito', 'qeperf');
+ }
+
+ if (!more || false === more) {
+ adapter.done('', meta);
+ }
+ };
- this._getTemplateObj(tmpl, !meta.view.cacheTemplates, handler);
+ this._getTemplateObj(tmpl, !cacheTemplates, handler);
},
/**

2 comments on commit c9cfcf1

Contributor

rwaldura replied Sep 11, 2012

doesn't this fix issue #408?

Collaborator

mridgway replied Sep 11, 2012

This fixes an issue that was caused by #408.

Please sign in to comment.