How can I disable reactivity of reactive data source?


#1

Hi,

Suppose that I have two reactive data source, for example, Session.get(‘A’) and Session.get(‘B’).

I want an autorun that refers these two session variables and will be reactively computed triggering by the Session.get(‘A’) only.

Are there any ways to disable reactivity of Session.get(‘B’)?


#2

Hi @new3rs,

According to documentation, you can use Tracker.nonreactive function - http://docs.meteor.com/#/full/tracker_nonreactive. Example:

Template.Foo.onCreated(function () {
  this.autorun(function () {
    var session_A = Session.get('A');
    var session_B = Tracker.nonreactive(function () {
      return Session.get('B');
    });
  });
});

#3

Thank you, amigasan!

I read meteor doc so many times but I have never seen this fuction^^;

Thanks, again.


#5

I am quite sure that Tracker.nonreactive() has no return value, hence the session_b assignation should be done in the callback function, like this:

Tracker.nonreactive(function(){
   var session_B = Session.get('b);
   // then do stuff with session_B
});

#6

And I am 100% sure, that Tracker.nonreactive has return value :wink:

http://meteorpad.com/pad/vPpTRCp6oe4SSxEna/tracker-nonreactive


#7

Didn’t know about that !


#8

What would happen in this case?

 collection() {
        return Comments.find({},{reactive: false});
      },
      comments() {
        var comments = this.getReactively('collection');
}

The comment helper is not calling itself again when collection is ready

And also if I desactive the reactivity I get no content:

return Comments.find({},{reactive: false}).fetch().map(comment => {
   console.log(comment); // with reactive: true I see some data but no with false
});