What does api.imply do?

前端 未结 2 1175
时光说笑
时光说笑 2020-12-11 01:00

From the Meteor docs:

Give users of this package access to another package (by passing in the string packagename) or a collection of pack

相关标签:
2条回答
  • 2020-12-11 01:38

    If you have something in your app that consumes api from package:name and you install just package package:dependant which has a package:name as a dependency, but you don't use imply here, your api from package:name will not work in the app. It will work only in package:dependant package. You need use imply if you want to use something from package:name outside your package:dependant

    I don't know if this is clear ;)

    0 讨论(0)
  • 2020-12-11 01:41

    api.use gives a package access to other packages exported symbols.

    For example you need to api.use("random") (see how it's done in the accounts-base package) if you want to use the Random symbol in a package code (see how the random package.js is api.exporting Random).

    However, meteor adding accounts-base wouldn't give your whole application access to its used packages (random in this case). If your app needs random, you'd still need to meteor add it.


    api.imply on the other hand, gives the whole application access to that package exported symbols.

    For example, see how accounts-google is api.implying accounts-base.

    accounts-base is responsible for exporting the Accounts symbol, when you meteor add accounts-google, not only does accounts-base is also added in your application dependencies, but accounts-base symbols are also made available in your app, specifically because it was implied.


    accounts-base is both using Accounts in its own code (api.use) and exporting its dependencies symbols to the whole app (api.imply).

    api.imply can be used to make "shadow packages" that are just pulling in some other packages.

    For example, at some point MDG renamed the showdown package to markdown, they could just have stated to meteor remove showdown && meteor add markdown, but it would have required some actions on end users.

    What they did instead is keeping the showdown package and just make it implying the new markdown package.

    0 讨论(0)
提交回复
热议问题