Reputation: 849
In one of my templates I use autorun to change some DOM elements when the data context changes, but it never gets triggered.
Template.onRendered(function () {
this.autorun(function () {
var someData = Template.currentData().someData;
// some DOM manipulation
}
}
The documentation states that Template.currentData():
Establishes a reactive dependency on the result.
So if someData
is being changed, it should trigger a recomputation, shouldn't it?
Upvotes: 1
Views: 535
Reputation: 849
After doing some research and getting a better understanding of reactive data sources and reactive computations and the underlying Tracker and Autorun I figured out, that I just needed to change
var someData = Template.currentData().someData;
to
var currentData = Template.currentData();
var someData = currentData.someData;
So it seems that only Template.currentData()
is a reactive data source, but the properties of the object it returns are not.
One could probably change that using reactive-var.
Upvotes: 2