Hello,
Here is the question I posted on Stack Overflow about this:
I’m basically trying to find a way to execute reactive functions only when part of a document inside of a minimongo collection has changed. I thought I had this done by narrowing my template’s autorun reactive variable down to the templates CurrentData. So if the data context of my template is strictly related to one array in my collection’s document, I should in theory only have my function execute when that array is modified. Unfortunately, no matter where I make changes in the collection all of the child template’s autoruns get executed.
Here is some code and I’d appreciate any ideas on the topic!
parent.html
{{#each items}}
{{> child}}
{{/each}}
child.html
<div>{{title}}</div>
<p>{{description}}</p>
Minimongo Collection
LocalProject.findOne() output:
"items": [
{
"title": hi,
"description": "test"
},
{
"title": hi 2,
"description": "test 2"
},
],
"otherstuff:{//etc}
child.js
Template.child.onRendered(function(){
this.autorun(function() {
var data = Template.currentData();
doSomething(data.title,data.description)
});
});
addnewitem.js
LocalProject.update(currentEditingProjectID,{ $push: { 'items': newItem }},function(error,result){
if(error){console.log(error)}
});