Class EventbusSecure
Index
Constructors
Accessors
Methods
Constructors
constructor
- new
Eventbus (): EventbusSecureSecure Returns EventbusSecure
Accessors
isDestroyed
- get isDestroyed(): boolean
Returns whether this instance has already been destroyed.
Returns boolean
Is destroyed state.
name
- get name(): string
Returns the name associated with this instance.
Returns string
The target eventbus name.
Methods
getOptions
- get
Options (name): EventOptionsOut Returns the options of an event name.
Parameters
- name: string
Event name(s) to verify.
Returns EventOptionsOut
The event options.
- name: string
getType
keys
keysWithOptions
- keys
With (regex?): Generator<[string, EventOptionsOut], void, unknown>Options Returns an iterable for the event names / keys of registered event listeners along with event options.
Parameters
Optional
regex: RegExpOptional regular expression to filter event names.
Returns Generator<[string, EventOptionsOut], void, unknown>
Generator
trigger
- trigger(name, ...args): EventbusSecure
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.
- name: string
triggerAsync
- trigger
Async (name, ...args): Promise<any> Provides
trigger
functionality, but collects any returned Promises from invoked targets and returns a single Promise generated byPromise.resolve
for a single value orPromise.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.
- name: string
triggerDefer
- trigger
Defer (name, ...args): EventbusSecure 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.
- name: string
triggerSync
- trigger
Sync (name, ...args): any 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.
- name: string
Static
initialize
- initialize(eventbus, name?): EventbusSecureObj
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.
Optional
name: stringIf 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.
- eventbus: EventbusProxy | Eventbus
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
andsetEventbus
. Expose to end consumers just theeventbusSecure
instance.