Reputation: 1322
So I've created an empty Meteor app. One of the files, server/main.js , looks like this:
import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
// code to run on server at startup
console.log('hello from the server');
});
I've tried commenting out the import statement above and the code still runs. So, are import statements, when importing meteor globals, only so it's more easy to see where the variable comes from? Does it make any difference, behaviorally, if I include that import statement or not?
Upvotes: 2
Views: 230
Reputation: 8439
The short answer: yes... and no.
From the Meteor Guide on importing Meteor globals: (emphasis mine)
For backwards compatibility Meteor 1.3 still provides Meteor’s global namespacing for the Meteor core package as well as for other Meteor packages you include in your application. You can also still directly call functions such as Meteor.publish, as in previous versions of Meteor, without first importing them. However, it is recommended best practice that you first load all the Meteor “pseudo-globals” using the import { Name } from 'meteor/package' syntax before using them. For instance:
import { Meteor } from 'meteor/meteor';
import { EJSON } from 'meteor/ejson';
It is, as they say, a best practice, as you saw that removing the import did not break your code. However, as you mentioned, there are some benefits:
Those are the two I can think of off hand I find valuable in my every-day work with Meteor.
Upvotes: 5