How Do I Make A Meteor Helper Non-Reactive?
Asked Answered
T

2

8

I want to make this code non reactive. Is there a way?

Template.foo.helpers({
    info: function(){
        var user = Meteor.user();
            if (user && user.profile)
                return user.profile.info;
    }
});

I know there is a way when you are Foo.find({}, {reactive:false})

I was wondering if there was a equivalent.

Transonic answered 22/3, 2015 at 17:1 Comment(0)
N
14

I think what you are looking for is the Tracker.nonreactive(func) function described here. Per the documentation, you need to pass a function to this function to be executed and the result of that function will be returned by this function. Also, this function will not pay attention to any reactive data source updates in your own defined function.

I would suggest rewriting your helper function like this:

Template.foo.helpers({
    info: function() {
        return Tracker.nonreactive(function() {
            var user = Meteor.user();
            if(user && user.profile) {
                return user.profile.info;
            } else {
                // return some other appropriate value if the if-statement above
                // is not fulfilled
            }
        });
    }
});
Numskull answered 12/6, 2015 at 1:58 Comment(0)
K
2

You're looking for Tracker.nonreactive (sorry for the poor answer, I'm using my phone).

Kamseen answered 22/3, 2015 at 17:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.