Last Updated on : 2024-06-05 03:14:36download
This topic describes the method that is used to listen for common events.
Request parameter
Parameter | Data type | Description | Required |
---|---|---|---|
yourEventName | string |
The event name. | Yes |
yourHandler | function |
The callback that is triggered by an event. | No |
Sample request
import { Utils } from "tuya-panel-kit";
TYSdk.event.on(yourEventName, yourHandler); // Enable event listening.
TYSdk.event.off(yourEventName, yourHandler); // Disable event listening.
TYSdk.event.emit(yourEventName, yourHandler); // Trigger an event.
/**
* @desc
* type: dpData The notification of the change in device status. The payload includes the updated data point (DP) status.
* type: devInfo The notification of the change in device information. The payload includes the value of `devInfo`.
* type: deviceOnline The notification to indicate whether the device is online. The payload is a Boolean value.
*/
on(
event: 'deviceDataChange',
callback: (data: {
type: 'dpData' | 'devInfo' | 'deviceOnline';
payload: Record<string, DpValue> | DevInfo | boolean;
}) => void,
): void;
/**
* @desc app The notification of the change in app network status.
*/
on(event: 'networkStateChange', callback: (data: { appOnline: boolean }) => void): void;
/**
* @desc The notification of the change in cloud timing status.
*/
on(event: 'linkageTimeUpdate', callback: (data: {}) => void): void;
/**
* @desc The notification of the change in device status in a local area network (LAN).
*/
on(event: 'deviceLocalStateChange', callback: (data: { state: boolean }) => void): void;
/**
* @desc The notification of the change in Bluetooth status.
*/
on(event: 'bluetoothChange', callback: (value: boolean) => void): void;
/**
* @desc A route of `NavigatorLayout` will render a specific component.
*/
on(event: 'NAVIGATOR_ON_WILL_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
/**
* @desc The route of `NavigatorLayout` completes the rendering task.
*/
on(event: 'NAVIGATOR_ON_DID_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
/**
* @desc
* type: dpData The notification of the change in device status. The payload includes the updated data point (DP) status.
* type: devInfo The notification of the change in device information. The payload includes the value of `devInfo`.
* type: deviceOnline The notification to indicate whether the device is online. The payload is a Boolean value.
*/
on(
event: 'deviceDataChange',
callback: (data: {
type: 'dpData' | 'devInfo' | 'deviceOnline';
payload: Record<string, DpValue> | DevInfo | boolean;
}) => void,
): void;
/**
* @desc The notification of the change in app network status.
*/
on(event: 'networkStateChange', callback: (data: { appOnline: boolean }) => void): void;
/**
* @desc The notification of the change in cloud timing status.
*/
on(event: 'linkageTimeUpdate', callback: (data: {}) => void): void;
/**
* @desc The notification of the change in device status in a local area network (LAN).
*/
on(event: 'deviceLocalStateChange', callback: (data: { state: boolean }) => void): void;
/**
* @desc The notification of the change in Bluetooth status.
*/
on(event: 'bluetoothChange', callback: (value: boolean) => void): void;
/**
* @desc A route of `NavigatorLayout` will render a specific component.
*/
on(event: 'NAVIGATOR_ON_WILL_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
/**
* @desc The route of `NavigatorLayout` completes the rendering task.
*/
on(event: 'NAVIGATOR_ON_DID_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
Note: When
componentWillUnmount
is called, you must disable event listening.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback