简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM