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:

Both options are used in the sample below.

Parameter

Name

Type

Description

name

string

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.
Options depend on the event.

Return value

Type

Description

TcHmi.DestroyFunction

Deregisters the event and releases all associated resources when called.

register 1:

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);