I need to limit the number of executions of an autorun function with a highly reactive data source.
Is it safe to assume I can do it this way?
Meteor.autorun(_.throttle(function() { var reactive = Session.get('highlyReactiveStuff'); // Do something }, 1000));
Isn’t there a built-in way to throttle autoruns otherwise?
I don’t think it will work, as I think your autorun function has nothing reactive inside. However you can do this:
autorun
var f = _.throttle(function() { /* Do something */ }, 1000); Meteor.autorun(function() { var reactive = Session.get('highlyReactiveStuff'); f(); });
Indeed that seems to work (passing the reactive data back to the function). Thanks!
var f = _.throttle(function(reactive) { /* Do something */ }, 1000); Meteor.autorun(function() { var reactive = Session.get('highlyReactiveStuff'); f(reactive); });