How to make the meteor helper inactive?

I want to make this code inactive. Is there any 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 Foo.find({}, {reactive:false})

I was wondering if there is an equivalent.

+6
source share
2 answers

I think you are looking for the Tracker.nonreactive(func) function described here . In the documentation, you need to pass a function to this function that will be executed, and the result of this function will be returned by this function. In addition, this function will not pay attention to any updates to reactive data sources in your specific function.

I would suggest rewriting your helper function as follows:

 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 } }); } }); 
+10
source

You are looking for Tracker.nonreactive (sorry for the poor answer, I use my phone).

+2
source

Source: https://habr.com/ru/post/984109/


All Articles