How can I export from a Meteor package into my app's namespace?

后端 未结 3 485
渐次进展
渐次进展 2021-02-05 21:25

I know how to write Meteor packages but I can\'t seem to figure out how to have all exports land in my app\'s namespace, as described in this presentation.

This particul

3条回答
  •  长发绾君心
    2021-02-05 21:58

    The api.export method is only supported for top-level variables right now. It doesn't work for nested variables, because "it turned out that using deep exports was very confusing", and what would you expect MyApp.myMethod to appear as in the global namespace if you also exported MyApp.myOtherMethod?

    You should just export MyPackage, and then call MyPackage.myMethod(). A common approach is to do something like

    MyPackage = { 
        myMethod: someSecretMethodName,
        myOtherMethod: otherMethodName
    }
    

    And then call api.export("MyPackage"). This means that the exported names of variables don't necessarily have to be what you called them. This is used a lot in the core meteor packages; you can also see an example at for MongoInternals in mongo_driver.js.

提交回复
热议问题