Api.imply() vs api.export() on package.js in meteor package?


#1

I try create the new package on meteor, but I don’t understand api.imply() and api.export().
Please help me.


#2

Simplified explanation (ignores versions, arrays of names, etc.):

api.export()

By default, any global objects or variables (declared without var) in your package are scoped to the package itself (they are not accessible from anywhere else). In order that your application can see these objects, you use api.export() with the name of the exposed object in quotes, i.e. as a string:

api.export('SomeObjectName');

api.imply()

Your package may require access to another package (let’s call this bob:bobpack), for which you will use api.use('bob:bobpack'). This will allow your package to access the exported objects provided by bob:bobpack, but will not allow any access outside of the package (e.g. from within your app’s main code).

To provide this access you use api.imply('bob:bobpack'): now your app’s code can directly use the exported objects provided by bob:bobpack.


#3

Thanks for your reply.
If i have

api.use('underscorestring:underscore.string')

So my package can use this package, but my app don’t.


#4

Correct (unless you also do a meteor add underscorestring:underscore.string) to your app.)

I guess you can think of imply doing the add for you.