Helper re-call after every change?


#1

Hey guys,
I’m having a little problem with my chat application. If a user types a message, I update a date object like this in the chat document:

Document

_id: 123
lastType: new Date()
users: [];

My router looks like this:

Router.route('/chat/:_id', {
name: 'chat',
data: function() { return Chats.findOne(this.params._id); },
waitOn: function() { return [subs.subscribe('chat',{id:this.params._id,limit:20})]; },
});

To get all messages, I’m using a helper like this:

Template.chat.helpers({ 'messages':function() { ...some other things... return Messages.find({chat_id:this._id});} });

Now I’m getting into trouble. Every time I change the “lastType” date object of my chat, the “message()” helper executes again. Is there any possibility to disable this, when I update the Date object?


#2

Okay, it’s all about reactivity :smiley:

Solved:

data: function() { return Chats.findOne(this.params._id); }

must be

data: function() { return Chats.findOne(this.params._id, {reactive:false}); }