How Do I Make A Meteor Helper Non-Reactive?

有些话、适合烂在心里 提交于 2019-11-27 06:52:21

问题


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.


回答1:


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
            }
        });
    }
});



回答2:


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



来源:https://stackoverflow.com/questions/29197247/how-do-i-make-a-meteor-helper-non-reactive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!