9

What is the difference between Meteor.autorun and Tracker.autorun?

  • are they just aliases?
  • is one deprecated?
  • is there any instance where one is preferable to the other?

I'm well aware of the difference in using this.autorun in template lifecycle callbacks, but have seen these two used interchangeably and just want to be sure I haven't missed a trick.

Kyll
  • 7,036
  • 7
  • 41
  • 64
bigmadwolf
  • 3,419
  • 3
  • 30
  • 44
  • I'm guessing that Tracker.autorun is the official reference since Meteor.autorun is not even mentioned in the official documentation (http://docs.meteor.com/#/full). – Jeroen Peeters Oct 24 '15 at 15:16
  • this is my assumption as well.....but assumptions make an ass out well... you know the rest. Any reference to what the deal is officially would be great, I know at some stage there was `deps.autorun` which i believe is now deprecated. – bigmadwolf Oct 24 '15 at 15:22

2 Answers2

16

Well, it can easily be found out with the identity operator.

This will be false because it is not the same function:

(function() {} === function() {})

Let's try with the two autorun :

(Meteor.autorun === Tracker.autorun)

This returns true. So yes it's only a pure alias.
However, only Tracker.autorun is documented. I suspect some kind of old API left for compatibility...
Let's check some Meteor code on GitHub!

File : deprecated.js

Meteor.autorun = Tracker.autorun;

This is in deprecated.js, it says some things about //Deprecated functions and some backward compatibility with Meteor 0.5.4. It seems pretty clear which one you should use.
You can find some other old timers in there, such as Deps...

Kyll
  • 7,036
  • 7
  • 41
  • 64
0

Try to run Meteor.autorun(); in the console, it throws the following error Uncaught Error: Tracker.autorun requires a function argument like you were trying to run Tracker.autorun();