PluginInvokeSupport adds direct method invocation support to PluginManager via the eventbus and alternately through a wrapped instance of PluginManager depending on the use case.

There are two types of invocation methods the first spreads an array of arguments to the invoked method. The second constructs a PluginInvokeEvent to pass to the method with a single parameter.

TODO: more info and wiki link

When added to a PluginManager through constructor initialization the following events are registered on the plugin manager eventbus:

plugins:async:invoke - PluginInvokeSupport#invokeAsync

plugins:async:invoke:event - PluginInvokeSupport#invokeAsyncEvent

plugins:get:method:names - PluginInvokeSupport#getMethodNames

plugins:has:method - PluginInvokeSupport#hasMethod

plugins:invoke - PluginInvokeSupport#invoke

plugins:sync:invoke - PluginInvokeSupport#invokeSync

plugins:sync:invoke:event - PluginInvokeSupport#invokeSyncEvent

// One can also indirectly invoke any method of the plugin.
// Any plugin with a method named `aCoolMethod` is invoked.
eventbus.triggerSync('plugins:invoke:sync:event', { method: 'aCoolMethod' });

// A specific invocation just for the 'an-npm-plugin-enabled-module'
eventbus.triggerSync('plugins:invoke:sync:event', {
method: 'aCoolMethod',
plugins: 'an-npm-plugin-enabled-module'
});

// There are two other properties `copyProps` and `passthruProps` which can be set with object data to _copy_ or
// _pass through_ to the invoked method.
Implements

Constructors

Accessors

  • get isDestroyed(): boolean
  • Returns whether the associated plugin manager has been destroyed.

    Returns boolean

    Returns whether the plugin manager has been destroyed.

Methods

  • Destroys all managed plugins after unloading them.

    Parameters

    • opts: {
          eventbus: Eventbus;
          eventPrepend: string;
      }

      An options object.

      • eventbus: Eventbus

        The eventbus to disassociate.

      • eventPrepend: string

        The current event prepend.

    Returns Promise<void>

  • Returns method names for a specific plugin, list of plugins, or all plugins. The enabled state can be specified along with sorting methods by plugin name.

    Parameters

    • Optionalopts: {
          enabled?: boolean;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object. If undefined all plugin data is returned.

      • Optionalenabled?: boolean

        If enabled is a boolean it will return plugin methods names given the respective enabled state.

      • Optionalplugins?: string | Iterable<string, any, any>

        Plugin name or iterable list of names.

    Returns string[]

    A list of method names

  • Checks if the provided method name exists across all plugins or specific plugins if defined.

    Parameters

    • opts: {
          method: string;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object.

      • method: string

        Method name to test.

      • Optionalplugins?: string | Iterable<string, any, any>

        Plugin name or iterable list of names to check for method. If undefined all plugins must contain the method.

    Returns boolean

    • True method is found.
  • This dispatch method simply invokes any plugin targets for the given method name.

    Parameters

    • opts: {
          args?: any[];
          method: string;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object.

      • Optionalargs?: any[]

        Method arguments. This array will be spread as multiple arguments.

      • method: string

        Method name to invoke.

      • Optionalplugins?: string | Iterable<string, any, any>

        Specific plugin name or iterable list of plugin names to invoke.

    Returns void

  • This dispatch method is asynchronous and adds any returned results to an array which is resolved via Promise.all Any target invoked may return a Promise or any result.

    Parameters

    • opts: {
          args?: any[];
          method: string;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object.

      • Optionalargs?: any[]

        Method arguments. This array will be spread as multiple arguments.

      • method: string

        Method name to invoke.

      • Optionalplugins?: string | Iterable<string, any, any>

        Specific plugin name or iterable list of plugin names to invoke.

    Returns Promise<any>

    A single result or array of results.

  • This dispatch method synchronously passes to and returns from any invoked targets a PluginEvent.

    Parameters

    • opts: {
          copyProps?: object;
          method: string;
          passthruProps?: object;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object.

      • OptionalcopyProps?: object

        Properties that are copied.

      • method: string

        Method name to invoke.

      • OptionalpassthruProps?: object

        Properties that are passed through.

      • Optionalplugins?: string | Iterable<string, any, any>

        Specific plugin name or iterable list of plugin names to invoke.

    Returns Promise<object>

    The PluginEvent data.

  • This dispatch method synchronously passes back a single value or an array with all results returned by any invoked targets.

    Parameters

    • opts: {
          args?: any[];
          method: string;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object.

      • Optionalargs?: any[]

        Method arguments. This array will be spread as multiple arguments.

      • method: string

        Method name to invoke.

      • Optionalplugins?: string | Iterable<string, any, any>

        Specific plugin name or iterable list of plugin names to invoke.

    Returns any

    A single result or array of results.

  • This dispatch method synchronously passes to and returns from any invoked targets a PluginEvent.

    Parameters

    • opts: {
          copyProps?: object;
          method: string;
          passthruProps?: object;
          plugins?: string | Iterable<string, any, any>;
      }

      Options object.

      • OptionalcopyProps?: object

        Properties that are copied.

      • method: string

        Method name to invoke.

      • OptionalpassthruProps?: object

        Properties that are passed through.

      • Optionalplugins?: string | Iterable<string, any, any>

        Specific plugin name or iterable list of plugin names to invoke.

    Returns object

    The PluginEvent data.

  • Sets the eventbus associated with this plugin manager. If any previous eventbus was associated all plugin manager events will be removed then added to the new eventbus. If there are any existing plugins being managed their events will be removed from the old eventbus and then onPluginLoad will be called with the new eventbus.

    Parameters

    • opts: {
          newEventbus: Eventbus;
          newPrepend: string;
          oldEventbus: Eventbus;
          oldPrepend: string;
      }

      An options object.

      • newEventbus: Eventbus

        The new eventbus to associate.

      • newPrepend: string

        The new event prepend.

      • oldEventbus: Eventbus

        The old eventbus to disassociate.

      • oldPrepend: string

        The old event prepend.

    Returns void