From 8ea82bc94e21fd030714ae98ebbdba207fc064b9 Mon Sep 17 00:00:00 2001 From: Mitar Date: Sun, 10 May 2015 17:17:22 -0700 Subject: [PATCH 1/3] Use Blaze._getTemplate to allow resolving into Blaze Components. --- dynamic_template.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dynamic_template.js b/dynamic_template.js index dd39d1f..ea3c552 100644 --- a/dynamic_template.js +++ b/dynamic_template.js @@ -218,12 +218,29 @@ DynamicTemplate.prototype.renderView = function (template) { // is it a template name like "MyTemplate"? if (typeof template === 'string') { - tmpl = Template[template]; + if (Blaze._getTemplate) { + tmpl = Blaze._getTemplate(template, function () { + return Template.instance(); + }); + } + else { + // Backwards compatibility for Meteor < 1.2. + tmpl = Template[template]; + } - if (!tmpl) + if (!tmpl) { // as a fallback double check the user didn't actually define // a camelCase version of the template. - tmpl = Template[camelCase(template)]; + if (Blaze._getTemplate) { + tmpl = Blaze._getTemplate(camelCase(template), function () { + return Template.instance(); + }); + } + else { + // Backwards compatibility for Meteor < 1.2. + tmpl = Template[camelCase(template)]; + } + } if (!tmpl) { tmpl = Blaze.With({ From 45b60c7bed1d2fce5bcfd28d7ab552b9814f4fa9 Mon Sep 17 00:00:00 2001 From: Mitar Date: Sun, 10 May 2015 17:17:28 -0700 Subject: [PATCH 2/3] Use referential equality for template var. This makes things not rerender if the same template object is returned for a template. Template objects do not really change through their life. So we can just check references. Default reactive var equality returns false for all object comparisons, even if they are in fact equal. --- dynamic_template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_template.js b/dynamic_template.js index ea3c552..e7e86a3 100644 --- a/dynamic_template.js +++ b/dynamic_template.js @@ -121,7 +121,7 @@ DynamicTemplate.prototype.create = function (options) { this.isCreated = true; this.isDestroyed = false; - var templateVar = ReactiveVar(null); + var templateVar = ReactiveVar(null, function (a, b) {return a === b}); var view = Blaze.View('DynamicTemplate', function () { var thisView = this; From 568ddbc1f73dddbfc1bef200361a9e417d8de2db Mon Sep 17 00:00:00 2001 From: Mitar Date: Sun, 10 May 2015 21:03:42 -0700 Subject: [PATCH 3/3] Better to just pass self. --- dynamic_template.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamic_template.js b/dynamic_template.js index e7e86a3..9cbbaf4 100644 --- a/dynamic_template.js +++ b/dynamic_template.js @@ -220,7 +220,7 @@ DynamicTemplate.prototype.renderView = function (template) { if (typeof template === 'string') { if (Blaze._getTemplate) { tmpl = Blaze._getTemplate(template, function () { - return Template.instance(); + return self; }); } else { @@ -233,7 +233,7 @@ DynamicTemplate.prototype.renderView = function (template) { // a camelCase version of the template. if (Blaze._getTemplate) { tmpl = Blaze._getTemplate(camelCase(template), function () { - return Template.instance(); + return self; }); } else {