c9 / architect

A simple yet powerful plugin system for large-scale node applications
MIT License
982 stars 129 forks source link

Add a way to mark some of the dependencies as optional. #36

Open nightwing opened 10 years ago

nightwing commented 10 years ago

usecase:

Cloud9 ace plugin reloads document when file on disk changes. If diffing library is present, it can apply diff, to keep editor state like selection and folds. But in case there is no diffing library, simply setting value is good enough.

Now adding dependency on diffing plugin, will break all configs using ace, and will require all of them to either include the diffing lib, or to include mock plugin as a fallback.

I think this is bad because it makes local change in ace plugin, into breaking change for all its consumers. But If optional dependencies were supported, only apps that needed diffing, would include it and it would only require one if statement in the ace plugin.

janjongboom commented 9 years ago

We do this by emitting an event on the eventbus when architect is ready and pass the app as argument. This way you can do soft-dependencies:

    imports.eventbus.on('architect-ready', app => {
      var interval = app.services['gonzo-service/interval'];
    });