Make Template.instance() correct in this.autorun() in templates

A previous change decoupled "current view" from "current template instance".
The code made sure to preserve "current view" explicitly within
`this.autorun`, but now we need to do the same for "current template instance"
This commit is contained in:
Avital Oliver
2015-01-26 15:52:44 -08:00
parent 99ca826040
commit 5862ec0363

View File

@@ -174,9 +174,13 @@ Blaze.View.prototype.autorun = function (f, _inViewScope) {
throw new Error("Can't call View#autorun from a Tracker Computation; try calling it from the created or rendered callback");
}
var templateInstanceFunc = Blaze.Template._currentTemplateInstanceFunc;
var c = Tracker.autorun(function viewAutorun(c) {
return Blaze._withCurrentView(_inViewScope || self, function () {
return f.call(self, c);
return Blaze.Template._withTemplateInstanceFunc(templateInstanceFunc, function () {
return f.call(self, c);
});
});
});
self.onViewDestroyed(function () { c.stop(); });