Meteor Reactive Methods
Call methods synchronously inside Tracker.autorun.
Install with meteor add simple:reactive-method
Sometimes, you want to call a Meteor method inside of a template helper or Tracker.autorun computation, and get a return value. Now you can!
Before (doesn't work)
1Template.foo.helpers({ 2 methodResult: function () { 3 Meteor.call("myMethod", "a", "b", function (err, result) { 4 return result; // this doesn't work!!! 5 }); 6 } 7});
After (works!)
1Template.foo.helpers({ 2 methodResult: function () { 3 // Super fun! 4 return ReactiveMethod.call("myMethod", "a", "b"); 5 6 // Can also use 'apply' style 7 // return ReactiveMethod.apply("myMethod", ["a", "b"]); 8 } 9});
Invalidating method calls
Sometimes, you want to force a reactive method to get a new value from the server, even though the arguments are the same. In that case, use ReactiveMethod.invalidateCall
or ReactiveMethod.invalidateApply
, like so:
1// Will cause the helper above to rerun 2ReactiveMethod.invalidateCall("myMethod", "a", "b");