I'm writing a package that exposes a few Meteor.methods. Is there a smarter way to namespace them to the package than hardcoding their names like this?
Meteor.methods({
'my:package/methodName': function ...
})
A way to figure out the name of a package from inside its JavaScript files would be a good start.
Meteor methods are functions that are written on the server side, but can be called from the client side. On the server side, we will create two simple methods. The first one will add 5 to our argument, while the second one will add 10.
// Asynchronous call Meteor. call('foo', 1, 2, (error, result) => { ... }); If you do not pass a callback on the server, the method invocation will block until the method is complete. It will eventually return the return value of the method, or it will throw an exception if the method threw an exception.
That is generally how we namespace things today with Meteor.methods.
If you wanted to do something dynamically, you could do something like this:
var namespace = "my:package";
var myFunc = function() {/* Meteor Method Function Here */}
var meteorMethods = {};
meteorMethods[namespace + "uniqueFuncName"] = myFunc;
Meteor.methods(meteorMethods);
It isn't too pretty and you still need a way to get the package name... if you don't 'var' the namespace variable (in this example) it would be available throughout your package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With