Creates the event proxy with an existing instance of Eventbus.
The target eventbus instance.
Returns the current proxied eventbus callback count.
Returns the current proxied callback count.
Returns the current proxied eventbus event count.
Returns the current proxied event count.
Returns whether this EventbusProxy has already been destroyed.
Is destroyed state.
Returns the target eventbus name.
The target eventbus name.
Returns the current proxied callback count.
Returns the current proxied callback count.
Returns the current proxied event count.
Returns the current proxied event count.
Just like on
, but causes the bound callback to fire several times up to the count specified before being
removed. When multiple events are passed in using the space separated syntax, the event
will fire count times for every event you passed in, not once for a combination of all events.
Number of times the function will fire before being removed.
Event name(s) or event map.
Event callback function or context for event map.
Optional
context: objectEvent context
Optional
options: EventOptionsOut | EventOptionsEvent registration options.
This EventbusProxy instance.
Creates an EventbusProxy wrapping the backing Eventbus instance. An EventbusProxy proxies events allowing all listeners added to be easily removed from the wrapped Eventbus.
A new EventbusProxy for this eventbus.
Returns an iterable for all events from the proxied eventbus yielding an array with event name, callback function, and event context.
Optional
regex: RegExpOptional regular expression to filter event names.
Generator
Returns the options of an event name.
Event name(s) to verify.
The event options.
Returns whether an event name is guarded.
Event name(s) or event map to verify.
Optional
data: objectStores the output of which names are guarded.
Whether the given event name is guarded.
Returns an iterable for the event names / keys of registered event listeners along with event options.
Optional
regex: RegExpOptional regular expression to filter event names.
Generator
Remove a previously-bound proxied event binding.
Please see Eventbus#off.
This EventbusProxy
Bind a callback function to an object. The callback will be invoked whenever the event is fired. If you have a
large number of different events on a page, the convention is to use colons to namespace them: poll:start
, or
change:selection
.
Please see Eventbus#on.
Event name(s) or event map.
Event callback function or context for event map.
Optional
context: objectEvent context.
Optional
options: EventOptionsOut | EventOptionsEvent registration options.
This EventbusProxy
Just like on
, but causes the bound callback to fire only once before being removed. Handy for saying "the next
time that X happens, do this". When multiple events are passed in using the space separated syntax, the event
will fire once for every event you passed in, not once for a combination of all events
Event name(s) or event map.
Event callback function or context for event map.
Optional
context: objectEvent context
Optional
options: EventOptionsOut | EventOptionsEvent registration options.
This EventbusProxy instance.
Returns an iterable for all stored locally proxied events yielding an array with event name, callback function, and event context.
Optional
regex: RegExpOptional regular expression to filter event names.
Generator
Returns an iterable for the event names / keys of the locally proxied event names with event options.
Note: The event options returned will respect all the event options from a registered event on the main eventbus if applicable.
Optional
regex: RegExpOptional regular expression to filter event names.
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.
Event name(s)
Rest
...args: any[]Additional arguments passed to the event function(s).
This EventbusProxy.
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.
Event name(s)
Rest
...args: any[]Additional arguments passed to the event function(s).
A Promise returning any results.
Defers invoking trigger
. This is useful for triggering events in the next clock tick.
Event name(s)
Rest
...args: any[]Additional arguments passed to the event function(s).
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.
Event name(s)
Rest
...args: any[]Additional arguments passed to the event function(s).
An Array of returned results.
EventbusProxy provides a protected proxy of another Eventbus instance.
The main use case of EventbusProxy is to allow indirect access to an eventbus. This is handy when it comes to managing the event lifecycle for a plugin system. When a plugin is added it could receive a callback, perhaps named
onPluginLoaded
, which contains an EventbusProxy instance rather than the direct eventbus. This EventbusProxy instance is associated in the management system controlling plugin lifecycle. When a plugin is removed / unloaded the management system can automatically unregister all events for the plugin without requiring the plugin author doing it correctly if they had full control. IE This allows to plugin system to guarantee no dangling listeners.EventbusProxy provides the on / off, before, once, and trigger methods with the same signatures as found in Eventbus. However, the proxy tracks all added event bindings which is used to proxy between the target eventbus which is passed in from the constructor. All registration methods (on / off / once) proxy. In addition, there is a
destroy
method which will unregister all of proxied events and remove references to the managed eventbus. Any further usage of a destroyed EventbusProxy instance results in a ReferenceError thrown.Finally, the EventbusProxy only allows events registered through it to be turned off providing a buffer between any consumers such that they can not turn off other registrations made on the eventbus or other proxy instances.