EventbusSecure provides a secure wrapper around another Eventbus instance.

The main use case of EventbusSecure is to provide a secure eventbus window for public consumption. Only events can be triggered, but not registered / unregistered.

You must use the initialize method passing in an existing Eventbus instance as the eventbus reference is private. In order to secure the eventbus from unwanted access there is no way to access the eventbus reference externally from the EventbusSecure instance. The initialize method returns an EventbusSecureObj object which contains two functions to control the secure eventbus externally; destroy and setEventbus. Expose to end consumers just the eventbusSecure instance.

Constructors

Accessors

  • get isDestroyed(): boolean
  • Returns whether this instance has already been destroyed.

    Returns boolean

    Is destroyed state.

  • get name(): string
  • Returns the name associated with this instance.

    Returns string

    The target eventbus name.

Methods

  • Returns the options of an event name.

    Parameters

    • name: string

      Event name(s) to verify.

    Returns EventOptionsOut

    The event options.

  • Returns the trigger type of event name. Note: if trigger type is not set then undefined is returned for type otherwise 'sync' or 'async' is returned.

    Parameters

    • name: string

      Event name(s) to verify.

    Returns string

    The trigger type.

  • Returns an iterable for the event names / keys of secured eventbus event listeners.

    Parameters

    • Optionalregex: RegExp

      Optional regular expression to filter event names.

    Returns Generator<string, void, unknown>

  • Returns an iterable for the event names / keys of registered event listeners along with event options.

    Parameters

    • Optionalregex: RegExp

      Optional regular expression to filter event names.

    Returns Generator<[string, EventOptionsOut], void, unknown>

    Generator

  • Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks.

    Parameters

    • name: string

      Event name(s)

    • Rest...args: any[]

      Additional arguments passed to the event function(s).

    Returns EventbusSecure

    This instance.

  • Provides trigger functionality, but collects any returned Promises from invoked targets and returns a single Promise generated by Promise.resolve for a single value or Promise.all for multiple results. This is a very useful mechanism to invoke asynchronous operations over an eventbus.

    Parameters

    • name: string

      Event name(s)

    • Rest...args: any[]

      Additional arguments passed to the event function(s).

    Returns Promise<any>

    A Promise to returning any results.

  • Defers invoking trigger. This is useful for triggering events in the next clock tick.

    Parameters

    • name: string

      Event name(s)

    • Rest...args: any[]

      Additional arguments passed to the event function(s).

    Returns EventbusSecure

    This EventbusProxy.

  • Provides trigger functionality, but collects any returned result or results from invoked targets as a single value or in an array and passes it back to the callee in a synchronous manner.

    Parameters

    • name: string

      Event name(s)

    • Rest...args: any[]

      Additional arguments passed to the event function(s).

    Returns any

    An Array of returned results.

  • Creates the EventbusSecure instance with an existing instance of Eventbus. An object / EventbusSecureObj is returned with an EventbusSecure reference and two functions for controlling the underlying Eventbus reference.

    destroy() will destroy the underlying Eventbus reference. setEventbus(<eventbus>) will set the underlying reference.

    Parameters

    • eventbus: EventbusProxy | Eventbus

      The target eventbus instance.

    • Optionalname: string

      If a name is provided this will be used instead of eventbus name.

    Returns EventbusSecureObj

    The control object which contains an EventbusSecure reference and control functions.