Plugin dependencies

This unit provides information about the Orion's implementation of the plugin dependencies. The main goal of the implementation of this pattern is to get rid of the priorities one and use a better and solid approach to manage dependencies between plugins.

How it works

In order to have a clear picture about the plugins and the relation between them, we created a dependencies system in which you define explicitly if a plugin is dependant of another but also the functionalities you are consuming or producing by the plugin. In the other hand, we can decide if a plugin prefers to be started or even know if there is a circular dependency in their relation in order to manage a fix to avoid its related problems.

Last example scenario

Mike is using the methods package to register its functionalities. The metadata of the plugins should look like:

Copy
// Plugin 'mike'
{
  name: 'plugin-mike',
  version: '1.0.0',
  isOn: false,
  orion: {
    methodsHelper: {
      methods: {
        produces: ['sum', 'subs', 'mult']
      }
    }
  }
}

And Oscar is consuming one of those methods.

Copy
// Plugin 'oscar'
{
  name: 'plugin-oscar',
  version: '1.0.0',
  pluginDependencies: { 'plugin-mike': '1.0.0' },
  orion: {
    methodsHelper: {
      methods: {
        consumes: { 'plugin-mike': ['mult'] }
      }
    }
  }
}

So Mike is defining them on the class.

Copy
class Mike {
  constructor({ methodsHelper }: PluginDIO) {
    methodsHelper.register('sum', (a: number, b: number) => {
      console.log(a + b);
    });
    methodsHelper.register('subs', (a: number, b: number) => {
      console.log(a - b);
    });
    methodsHelper.register('mult', (a: number, b: number) => {
      console.log(a * b);
    });
  }
}

And Oscar is invoking a Mike's functionality,

Copy
class Oscar {
    private _methodsHelper: MethodsHelper;

    constructor({ methodsHelper }: PluginDIO) {
      this._methodsHelper = methodsHelper;
    }

    mult(a: number, b: number) {

      return this._methodsHelper.invoke('mult', a, b);

    }
  }

Finally, you will be able to create a instance of plugin Oscar and use mult functionality.

Copy
const pluginOscar = new Oscar();

pluginOscar.mult(4, 4);
// logs 16