The script object api.events is used for issuing and handling scheduled
or non-scheduled events as well as calling functions asynchronously.
api.events.raise
Raises the specified event. This function makes it possible to raise a copy of an existing event using a new target.
event
An event name or an existing event object. If this is a string, it is assumed
to be a custom event name. If this is the event object from context.event,
the event is re-raised using the supplied target. The target object receives
the event and the target of the event becomes the this pointer in ECMAScript
(self in Python).
target optional
The target of the event. If the event is being handled on the target, this
value gets assigned as the this pointer in ECMAScript (self in Python).
If the event is handled by a global handler, there is no this pointer pointer
or equivalent. The event target is accessible under context.event.target in
the handler in both cases.
params optional
A map of parameters to be added into the event. This is available under
context.event.params in the handler.
api.events.handle
Handles the specified event using a dynamic handler. Dynamically added events
must be named so that they can be replaced or deleted dynamically. Dynamic
handlers are permanently persistent against the API until they are deleted
using api.events.unhandle.
name
The name of the event handler.
event
The event to handle. This can be a string representing a custom event name or an object containing the properties:
cls - the class object or class name on which the event will be triggered.
The event property context.event.target is an instance of this class.operation - the event operation triggered against the target.function
The function to invoke when the event occurs. This function must not rely on locally set variables set within the context of the call to set the handler as these will most likely be missing when this function is triggered.
api.events.handlers
Returns the existing list of dynamic handlers.
event optional
The event being handled. This can be a string representing a custom event
name or an object containing the properties described in api.events.handle.
If this is not provided, all dynamic handlers are returned.
Returns an array of all handlers configured for the specified event. Each element has the following properties:
name - the name of the handler.event - the name of the custom event or an object containing the properties
described in api.events.handle.api.events.unhandle
Deletes the dynamic handler. If the handler is already in use, it will complete but subsequent events will not trigger the handler.
name
The name of the event handler to delete.