Event functions.
Example
var eventLib = require('/lib/xp/event');
Methods
(static) listener(params)
This function adds a event listener.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object | Listener parameters. Properties
|
Example
// Adds an event listener on all node events.
eventLib.listener({
type: 'node.*',
localOnly: false,
callback: function (event) {
log.info(JSON.stringify(event));
}
});
(static) send(event)
This function sends a custom event. All custom events are prefixed "custom.".
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
object | Event to send. Properties
|
Example
// Sends a custom event named "custom.myEvent".
eventLib.send({
type: 'myEvent',
distributed: false,
data: {
a: 1,
b: 2
}
});