user2191332
user2191332

Reputation: 1119

Meteor: reactive helper using Tracker.Dependency

I have a helper

Template.home.helpers({
  songId: function(){
    return SongManager.getSongId();
  },
});

that uses the getSongId method from the SongManager

SongManager = {
  init: function(songId){
    this.dep = new Tracker.Dependency;
  },
  getSongId: function(){
    this.dep.depend();
    return this.songId;
  },
  setSongId: function(arg){
    this.songId = arg;
    this.dep.changed();
  },
}

But it doesn't cause the template to update reactively when setSongId is called. Am I doing anything wrong? If I use Session.get and Session.set, then everything works properly.

SongManager = {
  init: function(songId){
  },
  getSongId: function(){
    return Session.get('songId');
  },
  setSongId: function(arg){
    Session.set('songId', arg);
  },
}

Upvotes: 1

Views: 1039

Answers (1)

Mário
Mário

Reputation: 1612

I solved it but I'm quite surprised but the results: Placing inside Meteor.startup() doesn't work. I need to investigate why, there's is something about Blaze that I don't know yet.

Check the repo I created for this: https://github.com/mariorodriguespt/stack-song-manager

Upvotes: 2

Related Questions