Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespace Meteor methods to package

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.

like image 471
Dan Dascalescu Avatar asked Dec 11 '14 02:12

Dan Dascalescu


People also ask

What is Meteor methods?

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.

How do I call Meteor method?

// 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.


1 Answers

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.

like image 174
Carsten Winsnes Avatar answered Oct 25 '22 03:10

Carsten Winsnes