register
[ Function ]
static register(
name: string,
callback: (e: EventProvider.Event, ...data: any[]) => void,
options?: object
): TcHmi.DestroyFunction;
Registers a callback to an event and returns a function for deregistering the event.
If an event is no longer needed it should be logged off to avoid mem leaks.
The system offers two ways to log out:
- Return value of the register call: For this the return value is stored and called in destroy of a control, for example.
- First parameter in the callback. For example, if a callback is to be called only once, the registration can be terminated within the callback.
Both options are used in the sample below.
Parameter
Name | Type | Description |
---|---|---|
name | Name of the event | |
callback | (e: EventProvider.Event, ...data: any[]) => void; | Callback function which should be called for these events. This function receives an event object and optional further parameters. Not all events supplies these. |
options [ optional ] Available from version 1.10 | object | JSON object with setting values. |
Return value
Type | Description |
---|---|
Deregisters the event and releases all associated resources when called. |
Available from 1.8 |
Sample - JavaScript
var destroyEvent = TcHmi.EventProvider.register(
'TcHmiButton.onPressed',
function (evt, data) {
// Do stuff
console.log(evt);
if(data){
// some events have custom data
console.log(data);
}
// …
// Destroy to free event resources if event is no longer needed.
evt.destroy();
}
);
var timeoutID = setTimeout(function () {
// Remove register after 5 seconds as an example
destroyEvent();
}, 5000);