Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #452 from mridgway/fix_hb

Remove call to flush for client side hb to prevent multiple done calls. This fixes a bug where calling flush would call the invoke handler on the client side.
  • Loading branch information...
commit 755806560eb66d8515544e1fb053c7d692dd950d 2 parents 1aaa066 + 1209222
@mridgway mridgway authored
View
32 lib/app/addons/view-engines/hb.client.js
@@ -31,24 +31,31 @@ YUI.add('mojito-hb', function(Y, NAME) {
* @param {string} tmpl The name of the template to render.
* @param {object} adapter The output adapter to use.
* @param {object} meta Optional metadata.
+ * @param {boolean} more Whether there is more to be rendered
*/
- render: function (data, mojitType, tmpl, adapter, meta) {
- var handler = function (err, obj) {
- if (err) {
- adapter.error(err);
- return;
- }
+ render: function (data, mojitType, tmpl, adapter, meta, more) {
+ var cacheTemplates = meta && meta.view && meta.view.cacheTemplates,
+ handler = function (err, obj) {
+ var output;
+
+ if (err) {
+ adapter.error(err);
+ return;
+ }
- if (obj) {
- adapter.flush(obj.compiled(data), meta);
+ output = obj.compiled(data);
Y.log('render complete for view "' +
tmpl + '"',
'mojito', 'qeperf');
- }
- adapter.done('', meta);
- };
- this._getTemplateObj(tmpl, !meta.view.cacheTemplates, handler);
+ if (more) {
+ adapter.flush(output, meta);
+ } else {
+ adapter.done(output, meta);
+ }
+ };
+
+ this._getTemplateObj(tmpl, !cacheTemplates, handler);
},
/**
@@ -63,6 +70,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) {
View
31 lib/app/addons/view-engines/hb.server.js
@@ -35,28 +35,31 @@ YUI.add('mojito-hb', function(Y, NAME) {
* @param {string} tmpl The name of the template to render.
* @param {object} adapter The output adapter to use.
* @param {object} meta Optional metadata.
- * @param {boolean} more
+ * @param {boolean} more Whether there is more to be rendered
*/
render: function (data, mojitType, tmpl, adapter, meta, more) {
- var handler = function (err, obj) {
- if (err) {
- adapter.error(err);
- return;
- }
+ var cacheTemplates = meta && meta.view && meta.view.cacheTemplates,
+ handler = function (err, obj) {
+ var output;
+
+ if (err) {
+ adapter.error(err);
+ return;
+ }
- if (obj) {
- adapter.flush(obj.compiled(data), meta);
+ output = obj.compiled(data);
Y.log('render complete for view "' +
tmpl + '"',
'mojito', 'qeperf');
- }
- if (!more || false === more) {
- adapter.done('', meta);
- }
- };
+ if (more) {
+ adapter.flush(output, meta);
+ } else {
+ adapter.done(output, meta);
+ }
+ };
- this._getTemplateObj(tmpl, !meta.view.cacheTemplates, handler);
+ this._getTemplateObj(tmpl, !cacheTemplates, handler);
},
/**
View
12 tests/unit/lib/app/addons/view-engines/test-hb.client.js
@@ -44,16 +44,12 @@ YUI({useBrowserConsole: true}).use(
view: {}
};
Y.Mock.expect(adapter, {
- method: 'flush',
+ method: 'done',
args: [Y.Mock.Value.String, meta],
run: function (output, metaResult) {
Y.Assert.areEqual('<div>test</div>', output);
}
});
- Y.Mock.expect(adapter, {
- method: 'done',
- args: ['', meta]
- });
this.viewEngine.render(data, 'test', 'oldObjNotation.hb.html', adapter, meta);
},
@@ -68,16 +64,12 @@ YUI({useBrowserConsole: true}).use(
view: {}
};
Y.Mock.expect(adapter, {
- method: 'flush',
+ method: 'done',
args: [Y.Mock.Value.String, meta],
run: function (output, metaResult) {
Y.Assert.areEqual('<div>test</div>', output);
}
});
- Y.Mock.expect(adapter, {
- method: 'done',
- args: ['', meta]
- });
this.viewEngine.render(data, 'test', 'dotNotation.hb.html', adapter, meta);
}
}));
Please sign in to comment.
Something went wrong with that request. Please try again.